Bug #73991 [NEW]: JSON_OBJECT_AS_ARRAY flag does not function.

From: Date: Wed, 25 Jan 2017 11:38:59 +0000
Subject: Bug #73991 [NEW]: JSON_OBJECT_AS_ARRAY flag does not function.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206942@lists.php.net to get a copy of this message
From: kruithne at gmail dot com Operating system: All PHP version: 7.1.1 Package: JSON related Bug Type: Bug Bug description:JSON_OBJECT_AS_ARRAY flag does not function. Description: ------------ The documentation states that the fourth parameter for json_decode() is a bit-mask value, it goes on to list two possible flags: JSON_OBJECT_AS_ARRAY and JSON_BIGINT_AS_STRING. Despite being redundant (superseded by the second parameter), the JSON_OBJECT_AS_ARRAY flag has no effect on the decoded result when supplied. Test script: --------------- <?php $json = '{"test": "From there to here, and here to there, funny things are everywhere.", "number": 12345678901234567890}'; // Prove json_decode is working by default. // Expected: object(stdClass) (2) {["test"] => string(67) ["number"] => float()} // Result: object(stdClass) (2) {["test"] => string(67) ["number"] => float()} $decoded = json_decode($json); var_dump($decoded); // Prove that passing bit-mask options works. // Expected: object(stdClass) (2) {["test"] => string(67) ["number"] => string(20)} // Result: object(stdClass) (2) {["test"] => string(67) ["number"] => string(20)} $decoded = json_decode($json, false, 512, JSON_BIGINT_AS_STRING); var_dump($decoded); // Prove that the second parameter works for associative conversion. // Expected: array(2) {["test"] => string(67) ["number"] => string(20)} // Result: array(2) {["test"] => string(67) ["number"] => string(20)} $decoded = json_decode($json, true, 512, JSON_BIGINT_AS_STRING); var_dump($decoded); // Attempt to use JSON_OBJECT_AS_ARRAY for associative conversion fails. // Expected: array(2) {["test"] => string(67) ["number"] => string(20)} // Result: object(stdClass) (2) {["test"] => string(67) ["number"] => string(20)} $decoded = json_decode($json, false, 512, JSON_OBJECT_AS_ARRAY); var_dump($decoded); Expected result: ---------------- object(stdClass) (2) {["test"] => string(67) ["number"] => float()} object(stdClass) (2) {["test"] => string(67) ["number"] => string(20)} array(2) {["test"] => string(67) ["number"] => string(20)} array(2) {["test"] => string(67) ["number"] => string(20)} Actual result: -------------- object(stdClass) (2) {["test"] => string(67) ["number"] => float()} object(stdClass) (2) {["test"] => string(67) ["number"] => string(20)} array(2) {["test"] => string(67) ["number"] => string(20)} object(stdClass) (2) {["test"] => string(67) ["number"] => string(20)} -- Edit bug report at https://bugs.php.net/bug.php?id=73991&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73991&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73991&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73991&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73991&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73991&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73991&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73991&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73991&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73991&r=support Expected behavior: https://bugs.php.net/fix.php?id=73991&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73991&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73991&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73991&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73991&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73991&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73991&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73991&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73991&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73991&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73991&r=mysqlcfg

« previous php.bugs (#206942) next »