Re: undefined var has a value
| From: | Rasmus Lerdorf | Date: | Fri, 30 Jun 2000 01:54:02 +0000 |
| Subject: | Re: undefined var has a value | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-767@lists.php.net to get a copy of this message | ||
> What's the value of the an undefined var in PHP?
>
> if $undefined has never been defined before and I do this
>
> ----------------------------
> if ($undefined == 0) echo "It has zero value";
> else echo "It has nozero value";
> ---------------------------
>
> It seems to return zero value.
> This is not documented in the online PHP manual.
> Should I be expecting this in future releases or is this just fluke?
It's not a fluke. It's like doing:
if('a'==0) echo "a is zero";
That doesn't mean that a is the same as zero, of course, but the numerical
equivalent of 'a' is 0 because PHP needs to convert one of the args in
order to do a sane comparison. (int)'a' ends up evaluating to 0. Same
goes for an undefined value.
There is a new operator in PHP 4 which does a strict equality on the two
arguments.
eg. if('a'===0) "a is zero";
You will note that this does not print "a is zero" like the == version
does.
-Rasmus