|  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
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
6 - 3 = ?
Subscribe to this entry?

 [2014-07-08 15:14 UTC] ryangrahamnc at gmail dot com
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}"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-11 18:49 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: bukka
 [2015-03-11 18:49 UTC]
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

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

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 03:01:27 2024 UTC