note 119097 deleted from function.json-decode by salathe

From: Date: Mon, 21 Sep 2020 15:00:41 +0000
Subject: note 119097 deleted from function.json-decode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215424@lists.php.net to get a copy of this message
Note Submitter: Antony ---- Tried this on PHP Version 5.3.3 and json_decode returns NULL: <?php $payload = '{"DATA":{"KEY":"VALUE"},"SOME_OTHER_DATA":["value1","value2"]}'; $results = json_decode($payload, true, 512, 0); var_dump($results); // NULL ?> But this works: <?php $payload = '{"DATA":{"KEY":"VALUE"},"SOME_OTHER_DATA":["value1","value2"]}'; $results = json_decode($payload, true); var_dump($results); // array(2) { ["DATA"]=> array(1) { ["KEY"]=> string(5) "VALUE" } ["SOME_OTHER_DATA"]=> array(2) { [0]=> string(6) "value1" [1]=> string(6) "value2" } } ?> Seems that json_decode doesn't work properly when passing defaults $depth (512) and $options (0) parameters. But the signature of json_decode is: mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] ) And the min required version of PHP is PHP 5 >= 5.2.0.

« previous php.notes (#215424) next »