Bug #66707 [Nab]: big int conversion on json_encode/json_decode

From: Date: Thu, 13 Feb 2014 11:38:00 +0000
Subject: Bug #66707 [Nab]: big int conversion on json_encode/json_decode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184286@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66707&edit=1 ID: 66707 User updated by: sergey dot shilko at gmail dot com Reported by: sergey dot shilko at gmail dot com Summary: big int conversion on json_encode/json_decode Status: Not a bug Type: Bug Package: JSON related Operating System: Linux PHP Version: 5.5.7 Block user comment: N Private report: N New Comment: okay then, so its expected. Already using strict datatypes to threat large numbers as strings. Thanks. Previous Comments: ------------------------------------------------------------------------ [2014-02-13 11:35:06] sergey dot shilko at gmail dot com echo json_last_error(); //0 echo json_last_error_msg(); //No error ------------------------------------------------------------------------ [2014-02-13 11:33:59] derick@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Your integer is larger than the 64bit signed range allows. PHP can not represent this as an int, and just as a float. ------------------------------------------------------------------------ [2014-02-13 11:19:30] sergey dot shilko at gmail dot com Trying to use: $encoded = json_encode($facebookIds, JSON_NUMERIC_CHECK); makes things even worse: samearray(2) { [0]=> float(4.8572380745623E+19) [1]=> string(20) "48572380745623087456" } array(2) { [0]=> float(4.8572380745623E+19) [1]=> float(4.8572380745623E+19) } It converts "big int" to float, but this is at least visible in var dump. ------------------------------------------------------------------------ [2014-02-13 11:12:17] sergey dot shilko at gmail dot com #$decoded = json_decode($encoded, false, 512, JSON_BIGINT_AS_STRING); Makes no difference. Test script output: array(2) { [0]=> float(4.8572380745623E+19) [1]=> string(20) "48572380745623087456" } array(2) { [0]=> float(4.8572380745623E+19) [1]=> string(20) "48572380745623087456" } Broken ------------------------------------------------------------------------ [2014-02-13 11:07:40] sergey dot shilko at gmail dot com Description: ------------ http://php.net/json_encode http://php.net/json_decode json_decode(json_encode(A)) != A json_encode + json_decode breaks large integers. Test script: --------------- <?php $facebookIds = array(48572380745623087456, '48572380745623087456'); $encoded = json_encode($facebookIds); $decoded = json_decode($encoded); var_dump($facebookIds); var_dump($decoded); if ($facebookIds != $decoded) { echo "\nBroken\n"; } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66707&edit=1

« previous php.bugs (#184286) next »