|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ryangrahamnc at gmail dot com
New email:
PHP Version: OS:


 [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-2023 The PHP Group
All rights reserved.
Last updated: Sun Sep 24 15:01:24 2023 UTC