You get a bonus - 1 coin for daily activity. Now you have 1 coin

PHP Expectations assert () - zero-cost assumptions in industry code

Lecture



Expectations are an improved, backward compatible version of the old assert () function. They allow you to make assumptions with zero cost in the industrial code and provide the ability to throw user exceptions in the event of a wait failure.

Together with the fact that the old API is supported, assert () is now a language construct that takes the first argument of the expression, and not just the lines to evaluate or logical values ​​to check.

<? php
ini_set ('assert.exception', 1);

class CustomError extends AssertionError {}

assert (false, new CustomError ('Some error message'));
?>

The result of this example:

 Fatal error: Uncaught CustomError: Some error message

A detailed description of this functionality, as well as instructions for configuring it for test and industrial environments, can be found in the Waiting section of the section on assert ().


Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Running server side scripts using PHP as an example (LAMP)

Terms: Running server side scripts using PHP as an example (LAMP)