© Mikael Olsson 2016

Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_31

31. Assertions

Mikael Olsson

(1)Hammarland, Finland

Assert is a debugging feature that can be used during development to ensure that a condition is always true. Any expression can be asserted, as long as it evaluates to either true or false.

// Make sure $myVar is setassert(isset($myVar));

Code assertions like this help validate that there are no execution paths that break the specified assumption. If this occurs, a warning showing the file and line number of the assertion is displayed, which makes it easy to locate and fix the mistake in the code.

Warning: assert(): Assertion failed in C:\xampp\htdocs\mypage.php on line 3

A description of the assertion ...

Get PHP 7 Quick Scripting Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.