note 14327 added to language.types.boolean.php
| From: | brooke at jump dot net | Date: | Thu, 26 Jul 2001 19:40:03 +0000 |
| Subject: | note 14327 added to language.types.boolean.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15880@lists.php.net to get a copy of this message | ||
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