Home » Php » JSON decode on empty string behaves differently with PHP 7

JSON decode on empty string behaves differently with PHP 7

Posted by: admin July 12, 2020 Leave a comment

Questions:

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.

How to&Answers:

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)