note 90779 deleted from function.is-null by danbrown
| From: | danbrown@php.net | Date: | Sat, 09 May 2009 18:56:43 +0000 |
| Subject: | note 90779 deleted from function.is-null by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154392@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
A difference between "is_null" and "empty" is the following: "is_null"
tests if an <i>expression</i> is null, while "empty" tests if a
<i>variable</i> has null value or is undefined. This has small
Experiment 1:
<?php
function test() { return null }
var_dump(is_null(test()); // display "true"
var_dump(empty(test()); // parse error, because "test()" is not a variable
?>
Experiment 2:
<?php
var_dump(empty($an_undefined_variable)); // display "true" since
"$an_undefined_variable" is not defined
var_dump(is_null($an_undefined_variable); // display "false", but throw a notice because
"$an_undefined_variable" is not defined.
?>