Result on PHP 5.6
json_decode('', true);
echo last_json_error(); // 0
Result on PHP 7.0
json_decode('', true);
echo last_json_error(); // 4
I checked the changelog of PHP 7 (https://github.com/tpunt/PHP7-Reference) and could not find the reason for that. JSON got replaced by JSOND but the BC breaks list does not mention that!?
To clarify: My question is not about valid/invalid JSON. It's about the behavior change of PHP I could not find.
The json_decode() function is used to decode or convert a JSON object to a PHP object.
If json_decode returns null is it because the database. json is not valid.
You just have to use json_decode() function to convert JSON objects to the appropriate PHP data type. Example: By default the json_decode() function returns an object. You can optionally specify a second parameter that accepts a boolean value. When it is set as “true”, JSON objects are decoded into associative arrays.
It was marked as a bug and was fixed: https://bugs.php.net/bug.php?id=68938
You can find change logs here: http://php.net/ChangeLog-7.php#7.0.0 (search for json_decode)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With