note 24806 deleted from language.types.boolean by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Thu, 29 Aug 2002 20:45:39 +0000 |
| Subject: | note 24806 deleted from language.types.boolean by jmcastagnetto | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-36008@lists.php.net to get a copy of this message | ||
Despite 1 and 2 can both be converted to a boolean as TRUE, they differ:
(1 == TRUE) will be true
(2 == TRUE) will be false!
In an expression with ==, where there's a numeric value and a boolean, the boolean is promoted
to the numeric type and the values are compared.
So never perform tests based on the equivalent numeric value of TRUE. Don't write:
if ($variable == TRUE)...
as the condition would be false if the variable contains something else than a TRUE boolean, or a
numeric value different of 1. Simply write:
if ($variable)...
or:
if (!empty($variable))...