ID: 40503 Updated by: [EMAIL PROTECTED] Reported By: mchenryc at gmail dot com -Status: Assigned +Status: Closed Bug Type: Output Control Operating System: Windows XP PHP Version: 5CVS-2007-02-16 (snap) Assigned To: iliaa New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-02-16 00:47:45] mchenryc at gmail dot com 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 this bug report at http://bugs.php.net/?id=40503&edit=1