Edit report at https://bugs.php.net/bug.php?id=60111&edit=1

 ID:                 60111
 Updated by:         larue...@php.net
 Reported by:        digit6 at gmail dot com
 Summary:            JSON_NUMERIC_CHECK option mangles certain values
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            JSON related
 Operating System:   FreeBSD
 PHP Version:        5.3.8
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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: 3434343434340000.

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":3434343434340000}


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=60111&edit=1

Reply via email to