note 16766 modified in language.types.null by danbrown

From: Date: Tue, 19 May 2009 14:22:40 +0000
Subject: note 16766 modified in language.types.null by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155747@lists.php.net to get a copy of this message
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. --was-- Nulls are almost the same as unset variables and it is hard to tell the difference without creating errors from the interpreter: $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. http://php.net/manual/en/language.types.null.php

« previous php.notes (#155747) next »