WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML


 

PHP 7 - Expectations


Expectations are a backwards good upgrade to the more established assert() function. Desire takes into consideration zero-cost affirmations underway code, and gives the capacity to throw custom special cases when the statement falls flat. attest() is currently a language construct, where the principal parameter is an articulation when contrasted with being a string or Boolean to be tried.


Configuration orders for assert()

Directive Default value Possible values
zend.assertions 1

1 − produce and execute code (improvement mode)

0 − produce code however hop around it at runtime

-1 − don't create code (generation mode)

assert.exception 0

1 − throw, when the attestation bombs, either by throwing the object gave as the exemption or by throwing another AssertionError object if special case was not provided.

0 − use or produce a Throwable as portrayed above, yet just creates a notice dependent on that object as opposed to throwing it (good with PHP 5 behaviour)

Parameters

  • assertion − The affirmation. In PHP 5, this must be either a string to be assessed or a Boolean to be tried. In PHP 7, this may likewise be any articulation that profits an esteem, which will be executed and the outcome is utilized to show whether the attestation succeeded or failed.

  • description − A discretionary depiction that will be incorporated into the disappointment message, if the declaration fails.

  • exception − In PHP 7, the second parameter can be a Throwable object rather than a graphic string, in which case this is the object that will be throwed, if the attestation falls flat and the assert.exception arrangement order is enabled.

Return Values

FALSE if the affirmation is false, TRUE otherwise.

Example

<?php 

ini_set('assert.exception', 1); 

class CustomError extends AssertionError {} 

assert(false, new CustomError('Custom Error Message!')); 

?>

It produces the accompanying program yield −

Fatal mistake: Uncaught CustomError: Custom Error Message! in...