note 14327 rejected and deleted from language.types.boolean.php by zak
| From: | zak@php.net | Date: | Fri, 27 Jul 2001 09:11:31 +0000 |
| Subject: | note 14327 rejected and deleted from language.types.boolean.php by zak | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-15924@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?