Re: difference between $foo and isset($foo)

From: Date: Thu, 18 Apr 2002 18:57:19 +0000
Subject: Re: difference between $foo and isset($foo)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-93581@lists.php.net to get a copy of this message
On Thu, 18 Apr 2002, Norman Zhang wrote: > I am looking at some codes. Some authors use $foo and isset($foo) > interchangeably. Just to want to make sure that the statement, > > if ($foo) { ... } > > is different from > > if (isset($foo)) { ... } > > Right? if ($foo) means variable exists and can be null. Whereas, isset($foo) > means that the value in $foo cannot be null? Not quite (or maybe I just don't understand your sentence). if ($foo) will be true if $foo has been set to some non-null (and non-zero) value. It will be false if $foo==null. On the other hand, if (isset($foo)) will be true will be true if any value at all has been assigned to $foo, including null or zero. It will only be false if $foo has never been assigned in this scope. However, bear in mind that ($foo) will still evaluate to null even in this case. miguel

« previous php.general (#93581) next »