From: mchenryc at gmail dot com Operating system: Windows XP PHP version: 5CVS-2007-02-16 (snap) PHP Bug Type: Output Control Bug description: json_encode integer conversion is inconsistent with PHP
Description: ------------ json_encode converts integers to string in a different way than PHP's integer to string conversion (at least on win32). PHP appears to either handle unsigned values, or use more bits to encode integers, where as json_encode converts them to floats, causing rounding errors. Reproduce code: --------------- function show_eq($x,$y) { echo "$x ". ($x==$y ? "==" : "!=") ." $y\n"; } $value = 0x7FFFFFFF; #2147483647; show_eq("$value", json_encode($value)); $value++; show_eq("$value", json_encode($value)); Expected result: ---------------- 2147483647 == 2147483647 2147483648 == 2147483648 Which shows both functions handling unsigned (or "long") integers. Or: 2147483647 == 2147483647 2147483650 == 2147483650 Which shows both functions converting to a float with less precision. Actual result: -------------- 2147483647 == 2147483647 2147483648 != 2147483650 My code makes use of the "long" or "unsigned" (not sure what's actually happening) ability of PHP for unix timestamps, which I would dearly love to see stay. The real issue is that the two functions behave in different ways, and should not. -- Edit bug report at http://bugs.php.net/?id=40503&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40503&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40503&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40503&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40503&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40503&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40503&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40503&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40503&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40503&r=support Expected behavior: http://bugs.php.net/fix.php?id=40503&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40503&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40503&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40503&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40503&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40503&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40503&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40503&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40503&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40503&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40503&r=mysqlcfg