assert_options
assert_options
Set/get the various assert flags
mixed **assert_options** int $option mixed $value
Set the various control options or just query
their current settings.
assert
Opmerking: > The use of is discouraged in favor of setting and getting the php.ini directives and with and , respectively.
assert_optionszend.assertionsassert.exceptionini_set``ini_get
Passing an empty string as resets the assert callback.
option
valueAn optional new value for the option.
The callback function set via or
should have the following signature:
`ASSERT_CALLBACK`assert.callback```php
void assert_callback string $file int $line $assertion string $description
`file`
The file where has been called.
`assert`
`line`
The line where has been called.
`assert`
`assertion`
Prior to PHP 8.0.0, the assertion which has been passed to ,
but only when the assertion is given as a string.
(If the assertion is a boolean condition, this parameter will be an empty string.)
As of PHP 8.0.0, this parameter is always null.
`assert`
`description`
The description that has been passed to .
`assert`
`value`
Returns the original setting of any option.
If is not a valid option a
is thrown.
`option``ValueError`
**Voorbeeld: example**
```php
<?php
// This is our function to handle
// assert failures
function assert_failure($file, $line, $assertion, $message)
{
echo "The assertion $assertion in $file on line $line has failed: $message";
}
// This is our test function
function test_assert($parameter)
{
assert(is_bool($parameter));
}
// Set our assert options
assert_options(ASSERT_ACTIVE, true);
assert_options(ASSERT_BAIL, true);
assert_options(ASSERT_WARNING, false);
assert_options(ASSERT_CALLBACK, 'assert_failure');
// Make an assert that would fail
test_assert(1);
// This is never reached due to ASSERT_BAIL
// being true
echo 'Never reached';
?>
assert