php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67592 Encode with JSON_BIGINT_AS_STRING doesn't add quotes on bigints on 64bit machin
Submitted: 2014-07-08 15:14 UTC Modified: 2015-03-11 18:49 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: ryangrahamnc at gmail dot com Assigned: bukka (profile)
Status: Wont fix Package: JSON related
PHP Version: 5.5.14 OS: Ubuntu 12.04 LTS 64bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ryangrahamnc at gmail dot com
New email:
PHP Version: OS:

 

 [2014-07-08 15:14 UTC] 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}"

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-11 18:49 UTC] bukka@php.net
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: bukka
 [2015-03-11 18:49 UTC] bukka@php.net
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".
 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jun 09 19:03:38 2023 UTC