rfc:json_throw_on_error

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
rfc:json_throw_on_error [2017/09/24 12:01] ajfrfc:json_throw_on_error [2017/09/24 14:47] – v1.0.2 ajf
Line 1: Line 1:
 ====== PHP RFC: JSON_THROW_ON_ERROR ====== ====== PHP RFC: JSON_THROW_ON_ERROR ======
-  * Version: 1.0.1+  * Version: 1.0.2
   * Date: 2017-09-10   * Date: 2017-09-10
   * Author: Andrea Faulds   * Author: Andrea Faulds
Line 12: Line 12:
  
 ===== Proposal ===== ===== Proposal =====
-This RFC instead proposes adding a new option flag value for <php>json_decode()</php> and <php>json_encode()</php>, <php>JSON_THROW_ON_ERROR</php>. When passed this flag, the error behaviour of these functions is changed. Instead of setting the global error state, they clear it (to avoid reading dirty values), and if an error occurs, throw a <php>JsonException</php> with the message and code set to whatever <php>json_last_error()</php> and <php>json_last_error_msg()</php> would otherwise be respectively. <php>JSON_PARTIAL_OUTPUT_ON_ERROR</php> would override and disable <php>JSON_THROW_ON_ERROR</php>, so that generic wrapper functions that always pass the <php>JSON_PARTIAL_OUTPUT_ON_ERROR</php> flag continue to support <php>JSON_PARTIAL_OUTPUT_ON_ERROR</php>+This RFC instead proposes adding a new option flag value for <php>json_decode()</php> and <php>json_encode()</php>, <php>JSON_THROW_ON_ERROR</php>. When passed this flag, the error behaviour of these functions is changed. The global error state is left untouched, and if an error occurs that would otherwise set itthese functions instead throw a <php>JsonException</php> with the message and code set to whatever <php>json_last_error()</php> and <php>json_last_error_msg()</php> would otherwise be respectively. <php>JSON_PARTIAL_OUTPUT_ON_ERROR</php> would override and disable <php>JSON_THROW_ON_ERROR</php>, so that generic wrapper functions that always pass the <php>JSON_PARTIAL_OUTPUT_ON_ERROR</php> flag continue to support <php>JSON_PARTIAL_OUTPUT_ON_ERROR</php>.
  
 <php>JsonException</php> would be a new class that subclasses <php>Exception</php>. <php>JsonException</php> would be a new class that subclasses <php>Exception</php>.
Line 66: Line 66:
 ===== Changelog ===== ===== Changelog =====
  
 +  * v1.0.2 - change behaviour to leave global error flag untouched, rather than clearing it
   * v1.0.1 - cover details of the patch not previously mentioned   * v1.0.1 - cover details of the patch not previously mentioned
   * v1.0 - initial version   * v1.0 - initial version
rfc/json_throw_on_error.txt · Last modified: 2017/10/22 18:44 by ajf