WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML


 

PHP 7 - Expectations




Expectation allows for zero-cost assertions in production code, and provides the ability to throw custom exceptions when the assertion fails.


The PHP 7 Configuration directives for assert() are:

zend.assertions

  • 0 − generate code but skip around it at runtime
  • -1 − in this mode not generate code
  • 1 − generate and execute code
  • 1 − throw

assert.exception

the default value is 0.

only generates a warning based on that object rather than throwing it just like PHP 5.






Parameters

assertion :- In the PHP 7 returns a value, which will be executed and the result is used to indicate whether the assertion succeeded or failed

description : - If the assertion fails. it will be show failure message.

exception: the assertion fails and the assert.exception configuration directive is enabled.

Example

<?php ini_set('assert.exception', 7); class CustomError extends AssertionError {} assert(false, new CustomError('Custom Error Message!')); ?>
Run example »