# RFC: JSON failure warnings

- Status: Withdrawn
- Authors: Craig Duncan php@duncanc.co.uk
- Date: 2017-07-28
- Version: 0.2
- Original: https://wiki.php.net/rfc/json_encode_decode_errors
- Page: https://externals.io/rfc/json_encode_decode_errors
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Discussions on the mailing list

- [json_encode() / json_decode() warnings](https://externals.io/message/100061.md) — started on 2017-07-27, 14 messages
- [\[RFC\] Raise warnings for json_encode() and json_decode() issues](https://externals.io/message/100071.md) — started on 2017-07-28, 9 messages

---

## Introduction

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.

## Proposal

This RFC proposes changing `json_encode()` and `json_decode()` to raise E\_WARNING whenever a failure occurs.

## Concerns

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'.

## Implementation

GitHub: <https://github.com/php/php-src/compare/master...duncan3dc:1392440050e0d2a033583be9b4cd72ece782f548>

## References

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

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