Req #67592 [Opn->Wfx]: Encode with JSON_BIGINT_AS_STRING doesn't add quotes on bigints on 64bit machin
| From: | bukka@php.net | Date: | Wed, 11 Mar 2015 18:49:21 +0000 |
| Subject: | Req #67592 [Opn->Wfx]: Encode with JSON_BIGINT_AS_STRING doesn't add quotes on bigints on 64bit machin | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191320@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67592&edit=1
ID: 67592
Updated by: bukka@php.net
Reported by: ryangrahamnc at gmail dot com
Summary: Encode with JSON_BIGINT_AS_STRING doesn't add quotes
on bigints on 64bit machin
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: JSON related
Operating System: Ubuntu 12.04 LTS 64bit
PHP Version: 5.5.14
-Assigned To:
+Assigned To: bukka
Block user comment: N
Private report: N
New Comment:
I'm not sure what you mean by bigint here.
For the decoder the bigint is a value bigger then MAX_LENGTH_OF_LONG as defined in
https://github.com/php/php-src/blob/589374d02723ad71a35e0512fdd65a1c7d18bf69/Zend/zend_long.h#L112
This means that a value that can be saved in zend_long is converted. In case of 64bit that max value
9223372036854775808 which is about 9.468 x bigger than value in your example. It means that such
value wouldn't be decoded as a string. You can easily see it in http://3v4l.org/2gND4
I think that having different definition of bigint for decoder and encoder is not a good idea. The
thing is that PHP does not have a native support for bigint which means that any value greater than
9223372036854775808 is converted to double and this options does not make sense for encoder though.
That's why I'm setting this as "Wont fix".
Previous Comments:
------------------------------------------------------------------------
[2014-07-08 15:14:09] ryangrahamnc at gmail dot com
Description:
------------
Normally JSON_BIGINT_AS_STRING is only used on decodes, but I think it's useful in encode as
well. i.e. for sending json to a javascript client, which would convert bigints to floats unless the
quotes were added.
Test script:
---------------
var_dump(json_encode(['a'=>974110684307885632], JSON_BIGINT_AS_STRING));
Expected result:
----------------
string(26) "{"a":"974110684307885632"}"
Actual result:
--------------
string(24) "{"a":974110684307885632}"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67592&edit=1