PHP RFC: Raise warnings for json_encode() and json_decode() issues

  • Version: 0.2
  • Date: 2017-07-28
  • Author: Craig Duncan php@duncanc.co.uk
  • Proposed version: PHP 7.3
  • Status: Withdrawn


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.

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)

PHP 7.3

Proposed Voting Choices

Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted'.



Initial discussion that led to this RFC's creation: https://externals.io/message/100061

Discussion thread: https://externals.io/message/100071

rfc/json_encode_decode_errors.txt · Last modified: 2017/09/22 13:28 by