[PHP-BUG] Bug #60111 [NEW]: JSON_NUMERIC_CHECK option mangles certain values
From: Operating system: FreeBSD PHP version: 5.3.8 Package: JSON related Bug Type: Bug Bug description:JSON_NUMERIC_CHECK option mangles certain values Description: json_encode will produce undesired results when used with JSON_NUMERIC_CHECK when one or more values is longer than 12 digits, ex: 3434343434343434. The resulting JSON encoded string has the above value listed as: 343434343434. Removing the JSON_NUMERIC_CHECK option fixes the problem, but then all other numeric values are returned as strings rather than integers. Test script: --- $test = array("test"=>3434343434343434); $test = json_encode($test, JSON_NUMERIC_CHECK); echo $test; Expected result: {"test":3434343434343434} OR {"test":"3434343434343434"} Actual result: -- {"test":343434343434} -- Edit bug report at https://bugs.php.net/bug.php?id=60111&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60111&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60111&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60111&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60111&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60111&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60111&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60111&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60111&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60111&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60111&r=support Expected behavior: https://bugs.php.net/fix.php?id=60111&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60111&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60111&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60111&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60111&r=php4 Daylight Savings:https://bugs.php.net/fix.php?id=60111&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60111&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60111&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60111&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60111&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60111&r=mysqlcfg
Bug #60111 [Opn]: JSON_NUMERIC_CHECK option mangles certain values
Edit report at https://bugs.php.net/bug.php?id=60111&edit=1 ID: 60111 User updated by:digit6 at gmail dot com Reported by:digit6 at gmail dot com Summary:JSON_NUMERIC_CHECK option mangles certain values Status: Open Type: Bug Package:JSON related Operating System: FreeBSD PHP Version:5.3.8 Block user comment: N Private report: N New Comment: Incorrect ACTUAL output entered in bug, here is the real actual output: {"test":3.43434343434e+15} Previous Comments: [2011-10-21 22:56:05] digit6 at gmail dot com Description: json_encode will produce undesired results when used with JSON_NUMERIC_CHECK when one or more values is longer than 12 digits, ex: 3434343434343434. The resulting JSON encoded string has the above value listed as: 343434343434. Removing the JSON_NUMERIC_CHECK option fixes the problem, but then all other numeric values are returned as strings rather than integers. Test script: --- $test = array("test"=>3434343434343434); $test = json_encode($test, JSON_NUMERIC_CHECK); echo $test; Expected result: {"test":3434343434343434} OR {"test":"3434343434343434"} Actual result: -- {"test":343434343434} -- Edit this bug report at https://bugs.php.net/bug.php?id=60111&edit=1
Bug #60111 [Opn]: JSON_NUMERIC_CHECK option mangles certain values
Edit report at https://bugs.php.net/bug.php?id=60111&edit=1 ID: 60111 User updated by:digit6 at gmail dot com Reported by:digit6 at gmail dot com Summary:JSON_NUMERIC_CHECK option mangles certain values Status: Open Type: Bug Package:JSON related Operating System: FreeBSD PHP Version:5.3.8 Block user comment: N Private report: N New Comment: I would further like to add that even if I FORCE the numeric string to be of a string type in the array before passing it to json_encode(), the encode still treats the string encapsulated number as a LONG and not as a string. There is definitely a bug here. Previous Comments: [2011-10-22 00:17:18] digit6 at gmail dot com Incorrect ACTUAL output entered in bug, here is the real actual output: {"test":3.43434343434e+15} [2011-10-21 22:56:05] digit6 at gmail dot com Description: json_encode will produce undesired results when used with JSON_NUMERIC_CHECK when one or more values is longer than 12 digits, ex: 3434343434343434. The resulting JSON encoded string has the above value listed as: 343434343434. Removing the JSON_NUMERIC_CHECK option fixes the problem, but then all other numeric values are returned as strings rather than integers. Test script: --- $test = array("test"=>3434343434343434); $test = json_encode($test, JSON_NUMERIC_CHECK); echo $test; Expected result: {"test":3434343434343434} OR {"test":"3434343434343434"} Actual result: -- {"test":343434343434} -- Edit this bug report at https://bugs.php.net/bug.php?id=60111&edit=1
Bug #60111 [Fbk->Csd]: JSON_NUMERIC_CHECK option mangles certain values
Edit report at https://bugs.php.net/bug.php?id=60111&edit=1 ID: 60111 User updated by:digit6 at gmail dot com Reported by:digit6 at gmail dot com Summary:JSON_NUMERIC_CHECK option mangles certain values -Status: Feedback +Status: Closed Type: Bug Package:JSON related Operating System: FreeBSD PHP Version:5.3.8 Block user comment: N Private report: N New Comment: ^^ You are actually right on this. I was not taking into account that JSON_NUMERIC_CHECK's actual purpose is to look for strings of numeric values and automatically convert them to int values. In my example of forcing a string type on the numeric string, would still require NUMERIC_CHECK to reformat the var type. I was simply using JSON_NUMERIC_CHECK to ensure all my number values were integers, the fact that my platform may use a long set of numbers with no alpha chars in a "tracking number" field would break my implementation was not considered. I'm closing the bug, I'll have to just make sure I'm forcing int values where I require it manually. Thanks! Previous Comments: [2011-10-22 10:45:25] larue...@php.net I think your are running in 32-bit os, and I think it is not a bug, since the number value exceed the PHP_INT_MAX. -------- [2011-10-22 00:44:40] digit6 at gmail dot com I would further like to add that even if I FORCE the numeric string to be of a string type in the array before passing it to json_encode(), the encode still treats the string encapsulated number as a LONG and not as a string. There is definitely a bug here. -------- [2011-10-22 00:17:18] digit6 at gmail dot com Incorrect ACTUAL output entered in bug, here is the real actual output: {"test":3.43434343434e+15} ---------------- [2011-10-21 22:56:05] digit6 at gmail dot com Description: json_encode will produce undesired results when used with JSON_NUMERIC_CHECK when one or more values is longer than 12 digits, ex: 3434343434343434. The resulting JSON encoded string has the above value listed as: 343434343434. Removing the JSON_NUMERIC_CHECK option fixes the problem, but then all other numeric values are returned as strings rather than integers. Test script: --- $test = array("test"=>3434343434343434); $test = json_encode($test, JSON_NUMERIC_CHECK); echo $test; Expected result: {"test":3434343434343434} OR {"test":"3434343434343434"} Actual result: -- {"test":343434343434} -- Edit this bug report at https://bugs.php.net/bug.php?id=60111&edit=1