note 108104 deleted from language.operators.comparison by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 17:42:06 +0000 |
| Subject: | note 108104 deleted from language.operators.comparison by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217871@lists.php.net to get a copy of this message | ||
Note Submitter: Jeremy Swinborne
----
Beware of the consequences of comparing strings to numbers. You can disprove the laws of the
universe.
echo ('X' == 0 && 'X' == true && 0 == false) ? 'true ==
false' : 'sanity prevails';
This will output 'true == false'. This stems from the use of the UNIX function strtod()
to convert strings to numbers before comparing. Since 'X' or any other string without a
number in it converts to 0 when compared to a number, 0 == 0 && 'X' == true
&& 0 == false