note 90780 deleted from function.is-null by danbrown

From: Date: Sat, 09 May 2009 18:57:07 +0000
Subject: note 90780 deleted from function.is-null by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154394@lists.php.net to get a copy of this message
Note Submitter: claude dot pache at gmail dot com ---- A small but important difference between "is_null" and "empty" is the following: "is_null" tests if an *expression* is null, while "empty" tests if a *variable* is defined and has not a null value. The difference is manifested in the two following experiments: Experiment 1: <?php function test() { return null; } var_dump(is_null(test()); // displays "true" var_dump(empty(test()); // parse error, because "test()" is not a variable ?> Experiment 2: <?php error_reporting(E_ALL); var_dump(empty($an_undefined_variable)); // displays "true" since "$an_undefined_variable" is not defined var_dump(is_null($an_undefined_variable)); // displays "true", but throws a notice because "$an_undefined_variable" is not defined. ?>

« previous php.notes (#154394) next »