Edit report at https://bugs.php.net/bug.php?id=54547&edit=1
ID: 54547
Comment by: net at janoszen dot hu
Reported by: peter dot ritt at gmx dot net
Summary: wrong equality of string numbers
Status: Verified
Type: Bug
Package: Unknown/Other Function
Operating System: linux
PHP Version: 5.3.6
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Same problem:
php > var_dump('0xff' == '255');
bool(true)
Previous Comments:
------------------------------------------------------------------------
[2012-04-11 07:47:21] foobla at spambog dot com
I don't think it's about PHP_MAX_INT, rather about the maximum precision of a
double/float. "==" converts both strings to numbers (after spending CPU cycles
to detect whether they look like numbers), as described in
http://www.phpsadness.com/sad/47
once converted, the floats seem to actually *be* equal, even with "===":
php -r '
$a = (double)"9223372036854775807";
$b = (double)"9223372036854775808";
var_dump($a, $b, $a == $b, $a === $b);
'
float(9.2233720368548E+18)
float(9.2233720368548E+18)
bool(true)
bool(true)
------------------------------------------------------------------------
[2011-04-18 03:04:14] [email protected]
Maybe this should be Won't Fix to keep it consistent with 9223372036854775807
== 9223372036854775808 (with number literals).
------------------------------------------------------------------------
[2011-04-17 05:44:03] [email protected]
The following patch has been added/updated:
Patch Name: bug54547-2.diff
Revision: 1303011843
URL:
http://bugs.php.net/patch-display.php?bug=54547&patch=bug54547-2.diff&revision=1303011843
------------------------------------------------------------------------
[2011-04-17 01:59:59] [email protected]
The following patch has been added/updated:
Patch Name: bug54547.diff
Revision: 1302998399
URL:
http://bugs.php.net/patch-display.php?bug=54547&patch=bug54547.diff&revision=1302998399
------------------------------------------------------------------------
[2011-04-16 20:07:43] peter dot ritt at gmx dot net
Description:
------------
comparison of strings using == shows wrong results when both strings are
numbers (digits) around PHP_MAX_INT;
the same comparison using === works correctly;
tested on 64 bit systems only, affects also PHP 5.3.5
Test script:
---------------
$a = '9223372036854775807';
$b = '9223372036854775808';
if ($a == $b) {
echo "$a == $b\n";
}
else {
echo "$a != $b\n";
}
// displays 9223372036854775807 == 9223372036854775808
Expected result:
----------------
should display
9223372036854775807 != 9223372036854775808
Actual result:
--------------
displays
9223372036854775807 == 9223372036854775808
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54547&edit=1