From: oliver at teqneers dot de Operating system: Suse Linux 10/Debian Sarge PHP version: 5.1.2 PHP Bug Type: *General Issues Bug description: strange comparison on 64bit AMD
Description: ------------ When operating at or beyond the integer limits, there is a different behaviour between a 32bit and 64bit processor (beside the different max value of course). on a 32bit processor the limit is 2147483647, on a 64bit it is 9223372036854775807. if i try to compare a STRING value like "9223372036854775807" with a string value "9223372036854775808", which is higher, than the integer limit, the comparison between those two returns true, but it should be false. This problem seems also to exists in PHP 4.4.x. Reproduce code: --------------- 64-BIT-Source: -------------- <? echo 'max<br>'; echo PHP_INT_MAX.'<br>'; echo 'intval<br>'; echo intval(9223372036854775807).'<br>'; echo intval(9223372036854775808).'<br>'; echo intval(9223372036854775809).'<br>'; echo intval(9223372036854776832).'<br>'; echo intval(9223372036854776833).'<br>'; echo 'intval of string<br>'; echo intval('9223372036854775807').'<br>'; echo intval('9223372036854775808').'<br>'; echo intval('9223372036854775809').'<br>'; echo intval('9223372036854776832').'<br>'; echo intval('9223372036854776833').'<br>'; echo 'compares<br>'; if( '9223372036854775808' == '9223372036854775807' ) { echo 'wrong<br>'; } if( '9223372036854775808' == '9223372036854775806' ) { echo 'wrong<br>'; } if( 9223372036854775808 == 9223372036854775806 ) { echo 'wrong<br>'; } if( strval('9223372036854775808') == strval('9223372036854775806') ) { echo 'wrong<br>'; } if( (string)'9223372036854775808' == (string)'9223372036854775806' ) { echo 'wrong<br>'; } if( (string)'9323372036854775806' == (string)'9223372036854775806' ) { echo 'works fine<br>'; } ?> 32-BIT-Source: -------------- <? echo 'max<br>'; echo PHP_INT_MAX.'<br>'; echo 'intval<br>'; echo intval(2147483647).'<br>'; echo intval(2147483648).'<br>'; echo intval(2147483649).'<br>'; echo intval(2147483650).'<br>'; echo intval(2147483651).'<br>'; echo 'intval of string<br>'; echo intval('2147483647').'<br>'; echo intval('2147483648').'<br>'; echo intval('2147483649').'<br>'; echo intval('2147483650').'<br>'; echo intval('2147483651').'<br>'; echo 'compares<br>'; if( '2147483648' == '2147483647' ) { echo 'wrong<br>'; } if( '2147483648' == '2147483646' ) { echo 'wrong<br>'; } if( 2147483648 == 2147483646 ) { echo 'wrong<br>'; } if( strval('2147483648') == strval('2147483646') ) { echo 'wrong<br>'; } if( (string)'2147483648' == (string)'2147483646' ) { echo 'wrong<br>'; } ?> Expected result: ---------------- should be more or less equal to the 32-bit output, except of a higher number of course. Actual result: -------------- 64-BIT-Source: -------------- max 9223372036854775807 intval 9223372036854775807 -9223372036854775808 -9223372036854775808 -9223372036854775808 -9223372036854773760 intval of string 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 compares wrong wrong wrong wrong wrong 32-BIT-Source: -------------- max PHP_INT_MAX intval 2147483647 -2147483648 -2147483647 -2147483646 -2147483645 intval of string 2147483647 2147483647 2147483647 2147483647 2147483647 compares -- Edit bug report at http://bugs.php.net/?id=37082&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37082&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=37082&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37082&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37082&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37082&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37082&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37082&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37082&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37082&r=support Expected behavior: http://bugs.php.net/fix.php?id=37082&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37082&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37082&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37082&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37082&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37082&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37082&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37082&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37082&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37082&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37082&r=mysqlcfg