note 16766 deleted from language.types.null by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 10:55:36 +0000 |
| Subject: | note 16766 deleted from language.types.null by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210838@lists.php.net to get a copy of this message | ||
Note Submitter: dward at maidencreek dot com
----
Nulls are almost the same as unset variables and it is hard to tell the difference without creating
errors from the interpreter:
<?php
$var = NULL;
?>
isset($var) is FALSE
empty($var) is TRUE
is_null($var) is TRUE
isset($novar) is FALSE
empty($novar) is TRUE
is_null($novar) gives an Undefined variable error
$var IS in the symbol table (from get_defined_vars())
$var CAN be used as an argument or an expression.
So, in most cases I found that we needed to use !isset($var) intead of is_null($var) and then set
$var = NULL if the variable needs to be used later to guarantee that $var is a valid variable with a
NULL value instead of being undefined.