Whenever json_encode()
or json_decode()
are called, you must call json_last_error()
to check if a failure occurred.
This is unnecessarily complicated and is easy to be forgotten leading to bugs in code. Particular with new developers that aren't familiar with error handling techniques.
This RFC proposes changing json_encode()
and json_decode()
to raise E_WARNING whenever a failure occurs.
The functionality of json_last_error()
and json_last_error_msg()
are unaffected and they can still be used in exactly the same way they are today.
Existing code that is using json_last_error()
for error handling may need changing to handle the E_WARNING instead.
However it is expected that most code is either suppressing warnings, or converting them to exceptions with an exception handler.
It's also worth noting that json_decode()
already has 2 instances it raises E_WARNING.
PHP 7.3
Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted'.
GitHub: https://github.com/php/php-src/compare/master...duncan3dc:1392440050e0d2a033583be9b4cd72ece782f548
Initial discussion that led to this RFC's creation: https://externals.io/message/100061
Discussion thread: https://externals.io/message/100071