[prev in list] [next in list] [prev in thread] [next in thread]
List: php-db
Subject: Re: [PHP-DB] undefined var has a value
From: Rasmus Lerdorf <rasmus () php ! net>
Date: 2000-06-30 1:54:02
[Download RAW message or body]
> 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
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic