PHP RFC: Raise warnings for json_encode() and json_decode() issues
- Version: 0.2
- Date: 2017-07-28
- Author: Craig Duncan email@example.com
- Proposed version: PHP 7.3
- Status: Withdrawn
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_decode() to raise E_WARNING whenever a failure occurs.
The functionality of
json_last_error_msg() are unaffected and they can still be used in exactly the same way they are today.
Backward Incompatible Changes
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.
Proposed PHP Version(s)
Proposed Voting Choices
Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted'.