#40115 [NEW]: String Comparison shows odd results for integer values around -2^31

From: Date: Fri, 12 Jan 2007 22:19:44 +0000
Subject: #40115 [NEW]: String Comparison shows odd results for integer values around -2^31
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-107554@lists.php.net to get a copy of this message
From: jannisbreitwieser at web dot de Operating system: Linux 2.6 PHP version: 5.2.0 PHP Bug Type: Strings related Bug description: String Comparison shows odd results for integer values around -2^31 Description: ------------ <? $a = '-2147483648'; for ($a = -2147373648 ; $a > -2147483670; $a-=1000) { $a = (string) $a; $b = '50000'; echo $a > $b ? "$a - true\n" : "$a - false\n"; } ?> -> The comparison should always return false but it doesnt - for some reason some of the comparisons return true. Reproduce code: --------------- according to http://www.php.net/manual/en/language.operators.comparison.php Quote:"If you compare two numerical strings, they are compared as integers." This is not the case since $a = '-2147483648'; for ($a = -2147373648 ; $a > -2147483670; $a-=1000) { // No longer cast to string $b = '50000'; echo $a > $b ? "$a - true\n" : "$a - false\n"; } returns different values (which is 'false' as expected). -- Edit bug report at http://bugs.php.net/?id=40115&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40115&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40115&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40115&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40115&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40115&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40115&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40115&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40115&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40115&r=support Expected behavior: http://bugs.php.net/fix.php?id=40115&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40115&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40115&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40115&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40115&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40115&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40115&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40115&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40115&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40115&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40115&r=mysqlcfg

« previous php.bugs (#107554) next »