HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

assert_options

Description

The assert_options of Options / Information for PHP set/get the various assert flags.

Syntax

assert_options(int $what, mixed $value = ?): mixed

Parameters

what

OptionINI SettingDefault valueDescription
ASSERT_ACTIVEassert.active1enable assert() evaluation
ASSERT_WARNINGassert.warning1issue a PHP warning for each failed assertion
ASSERT_BAILassert.bail0terminate execution on failed assertions
ASSERT_CALLBACKassert.callback(null)Callback to call on failed assertions

value

An optional new value for the option.

The callback function set via ASSERT_CALLBACK or assert.callback should have the following signature:

assert_callback
(
    string $file,
    int $line,
    string $assertion,
    string $description = ?
): void

file

The file where assert() has been called.

line

The line where assert() has been called.

assertion

The assertion that has been passed to assert(), converted to a string.

description

The description that has been passed to assert().

Return

Returns the original setting of any option or false on errors.

Examples

1 · ASSERT_ACTIVE

<?

$what = ASSERT_ACTIVE;
$value = 1;

$return = assert_options($what, $value);

assert(true == false);

var_export($return);
1

2 · ASSERT_WARNING

<?

$what = ASSERT_WARNING;
$value = 1;

$return = assert_options($what, $value);

assert(true == false);

var_export($return);
1

3 · ASSERT_BAIL

<?

$what = ASSERT_BAIL;
$value = 0;

$return = assert_options($what, $value);

assert(true == false);

var_export($return);
0

4 · ASSERT_CALLBACK

<?

function assert_callback($file, $line, $assertion, $description)
{
    echo "file: $file\nline: $line\nassertion: $assertion\ndescription: $description";
}

$what = ASSERT_CALLBACK;
$value = 'assert_callback';

$return = assert_options($what, $value);

assert(true == false);

var_export($return);
NULL