php.net |  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
Votes:1
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
Description:
------------
---
From manual page: http://www.php.net/function.json-decode
---

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: http://stackoverflow.com/questions/30680565/json-decode-and-php-json-bigint-as-string-disparity

Test script:
---------------
<?php

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

Expected result:
----------------
object(stdClass)#1 (1) {
  ["number"]=>
  string(20) "12345678901234567890"
}

Actual result:
--------------
https://www.dropbox.com/s/dqquq13pjymeyrt/Screenshot%202015-06-06%2011.48.33.png?dl=0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-06 11:19 UTC] cmb@php.net
-Package: json +Package: PECL
 [2015-06-06 11:19 UTC] cmb@php.net
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
implemented:
<https://github.com/remicollet/pecl-json-c/commit/5822493892c65219db07378f22bb3b1ccb5fdd06>.
 [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] remi@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: remi
 [2015-06-07 17:35 UTC] remi@php.net
jsonc bug are manage on https://github.com/remicollet/pecl-json-c/issues
 [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] cmb@php.net
-Status: Assigned +Status: Closed
 [2015-06-08 14:57 UTC] cmb@php.net
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 README.md 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
<https://github.com/remicollet/pecl-json-c/issues>, as requested
by the package maintainer.

[1] <https://github.com/remicollet/pecl-json-c/blob/master/README.md>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 00:01:27 2024 UTC