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

assert

Description

The assert of Options / Information for PHP checks if assertion is false.

Syntax

assert(
    mixed $assertion,
    Throwable|string|null $description = null
): bool

Parameters

assertion

This is any expression that returns a value, which will be executed and the result is used to indicate whether the assertion succeeded or failed.

description

If description is an instance of Throwable, it will be thrown only if the assertion is executed and fails.

If description is a string this message will be used if an exception or a warning is emitted. An optional description that will be included in the failure message if the assertion fails.

If description is omitted. A default description equal to the source code for the invocation of assert() is created at compile time.

Return

Returns true if at least one of the following is true:

zend.assertions=0
zend.assertions=-1
A custom exception object is passed to description.

If none of the conditions are true, returns true if assertion is truthy and false otherwise.

Examples

1 · assertion

<?

$assertion = 1 > 2;

$return = assert($assertion);

var_export($return);
Fatal error: Uncaught AssertionError: assert(1 > 2)

2 · description · string

<?

$assertion = 1 > 2;
$description = "mystring";

$return = assert($assertion, $desctiption);

var_export($return);
Fatal error: Uncaught AssertionError: mystring