note 108264 added to types.comparisons
| From: | php at richardneill dot org | Date: | Thu, 12 Apr 2012 19:45:30 +0000 |
| Subject: | note 108264 added to types.comparisons | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187089@lists.php.net to get a copy of this message | ||
Be wary of string-comparison where both strings might be interpreted as numbers. Eg:
$x="123456789012345678901234567890"; $y="123456789012345678900000000000";
echo ($x==$y)?"equal":"not_equal"; #Prints equal !!
Both strings are getting converted to floats, then losing precision, then becoming equal :-(
Using "===" or making either of the strings non-numeric will prevent this.
[This is on a 32-bit machine, on a 64-bit, you will have to make the strings longer to see the
effect]
----
Server IP: 69.147.83.197
Probable Submitter: 78.32.19.201
----
Manual Page -- http://www.php.net/manual/en/types.comparisons.php
Edit -- https://master.php.net/note/edit/108264
Del: integrated -- https://master.php.net/note/delete/108264/integrated
Del: useless -- https://master.php.net/note/delete/108264/useless
Del: bad code -- https://master.php.net/note/delete/108264/bad+code
Del: spam -- https://master.php.net/note/delete/108264/spam
Del: non-english -- https://master.php.net/note/delete/108264/non-english
Del: in docs -- https://master.php.net/note/delete/108264/in+docs
Del: other reasons-- https://master.php.net/note/delete/108264
Reject -- https://master.php.net/note/reject/108264
Search -- https://master.php.net/manage/user-notes.php