Re: note 14327 added to language.types.boolean.php
| From: | Zak Greant | Date: | Fri, 27 Jul 2001 09:18:17 +0000 |
| Subject: | Re: note 14327 added to language.types.boolean.php | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-15925@lists.php.net to get a copy of this message | ||
Hi Brooke,
Sorry to remove your manual note - however, PHP does loose comparison by
default.
This means that 0, "", FALSE and NULL are all equivalent when comparing with
the loose comparison operators (==, !=, etc.)
If you want a better understanding of how PHP handles types, comparison
operators, etc. review the PHP Language Reference section of the online
manual (http://www.php.net/manual/en/langref.php)
--zak
----- Original Message -----
From: <brooke@jump.net>
To: <php-notes@lists.php.net>
Sent: Thursday, July 26, 2001 1:40 PM
Subject: [PHP-NOTES] note 14327 added to language.types.boolean.php
> People like to explicitly compare against TRUE or FALSE. However, this can
be dangerous. Most script languages (and I think PHP included) like to
promote the type with less range to the type with more range before
performing an operation. Thus, when comparing an integer with TRUE, you get
the equivalent of comparing with 1, which is certainly not what you meant.
After all, the number 2 is not equal to the number 1, although the number 2
is considered "true". Therefore, prefer the syntax:
>
> if ($foo) {// reliable}
> over
> if ($foo == TRUE) {// unpredictable}
>
> OK?
>
> http://www.php.net/manual/en/language.types.boolean.php
>
>
> --
> PHP Notes Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-notes-unsubscribe@lists.php.net
> For additional commands, e-mail: php-notes-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>