|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69763 Json-c is *not* a drop-in replacement
Submitted: 2015-06-06 09:51 UTC Modified: 2015-06-08 14:57 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bruno at skvorc dot me Assigned: remi (profile)
Status: Closed Package: PECL (PECL)
PHP Version: 5.6.9 OS: All
Private report: No CVE-ID: None
 [2015-06-06 09:51 UTC] bruno at skvorc dot me
From manual page:

In example #5, BIGINT is converted to string using the JSON_BIGINT_AS_STRING flag. However, when using Remi's pecl extension (the drop in replacement), this will fail and report an integer overflow notice for numbers larger than signed max integer (like the one in the json_decode documents).

Obviously, this is an edge case, but it still *can* and *does* affect some implementations - the API of the company I'm building a lib for sometimes returns unsigned 64bit integers, and thus this will break. Since we're dealing with JSON, the notice headers will break things and make my app unusable unless I use the silence operator(@).

More details here:

Test script:

var_dump(json_decode('{"number": 12345678901234567890}', false, 512, JSON_BIGINT_AS_STRING));

Expected result:
object(stdClass)#1 (1) {
  string(20) "12345678901234567890"

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-06 11:19 UTC]
-Package: json +Package: PECL
 [2015-06-06 11:19 UTC]
Actually, the package should be "jsonc", but unfortunately that is
not available from the list, so I've changed to "PECL".

Anyhow, it seems that JSON_BIGINT_AS_STRING is not (yet) fully
 [2015-06-06 11:30 UTC] bruno at skvorc dot me
Fair, but until it is, this disparity should be noted in the PHP docs and using it as a drop-in replacement should be discouraged because there is no feature-for-feature parity. It just doesn't work as documented, simple as that.
 [2015-06-07 17:35 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: remi
 [2015-06-07 17:35 UTC]
jsonc bug are manage on
 [2015-06-07 18:59 UTC] bruno at skvorc dot me
-Status: Closed +Status: Assigned
 [2015-06-07 18:59 UTC] bruno at skvorc dot me
I would suggest this remain open because it is as much a bug in jsonc as it is a bug of the PHP docs - example 5 MUST be rectified.
 [2015-06-08 14:57 UTC]
-Status: Assigned +Status: Closed
 [2015-06-08 14:57 UTC]
I don't agree that this is a problem of the JSON documentation in
the PHP manual, because it documents the ext/json extension, and
not other alternative implementations (one can even think of JSON
replacements written in userland).

Of course, it seems to be reasonable that alternative
implementations point out differences. However, that is already
done in of the pecl-json-c[1]:

| json_decode use the json-c library and is mostly compatible.
| * > 64 bits integer are always parsed as integer (never float or
|   string)

Please file bugs related to json-c (including its PECL page) to
<>, as requested
by the package maintainer.

[1] <>
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Jul 11 18:01:24 2020 UTC