note 90782 modified in function.is-null by danbrown

From: Date: Sat, 09 May 2009 18:57:01 +0000
Subject: note 90782 modified in function.is-null by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154393@lists.php.net to get a copy of this message
A small but important difference between "is_null" and "isset" is the following: "is_null" tests if an *expression* (not a *variable*) is null, while "isset" tests if a *variable* has null value or is undefined. 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(isset(test())); // parse error, because "test()" is not a variable ?> Experiment 2: <?php error_reporting(E_ALL); var_dump(isset($an_undefined_variable)); // displays "false" since "$an_undefined_variable" is not defined var_dump(is_null($an_undefined_variable)); // displays "true" (as expected), but throws a notice because "$an_undefined_variable" is not defined. ?> --was-- [Note. A manipulation error has caused submission of incomplete/bogus versions of my note.] A small but important difference between "is_null" and "isset" is the following: "is_null" tests if an *expression* (not a *variable*) is null, while "isset" tests if a *variable* has null value or is undefined. 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(isset(test())); // parse error, because "test()" is not a variable ?> Experiment 2: <?php error_reporting(E_ALL); var_dump(isset($an_undefined_variable)); // displays "false" since "$an_undefined_variable" is not defined var_dump(is_null($an_undefined_variable)); // displays "true" (as expected), but throws a notice because "$an_undefined_variable" is not defined. ?> http://php.net/manual/en/function.is-null.php

« previous php.notes (#154393) next »