====== PHP RFC: Raise warnings for json_encode() and json_decode() issues ====== * Version: 0.2 * Date: 2017-07-28 * Author: Craig Duncan * Proposed version: PHP 7.3 * Status: Withdrawn ===== 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