|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-05-09 15:56 UTC] requinix@php.net
-Summary: Json_last_error hugely suprising
+Summary: json_last_error should work even if
JSON_THROW_ON_ERROR
-Package: *General Issues
+Package: JSON related
[2019-05-09 16:13 UTC] cmb@php.net
[2019-05-09 16:50 UTC] danack@php.net
[2019-05-23 23:41 UTC] ajf@php.net
-Type: Bug
+Type: Feature/Change Request
[2019-05-24 00:47 UTC] ajf@php.net
[2024-09-05 20:52 UTC] cmb@php.net
-Status: Open
+Status: Duplicate
[2024-09-05 20:52 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 06:00:02 2025 UTC |
Description: ------------ When using JSON_THROW_ON_ERROR, json_last_error no longer refers to the previous function call, but instead the last json_(encode|decode) that doesn't have the JSON_THROW_ON_ERROR flag set. Test script: --------------- $foo = json_decode('[bar'); // many lines of code. $bar = json_encode('Hello world!', JSON_THROW_ON_ERROR); if (json_last_error() !== JSON_ERROR_NONE) { // Note, this is not true. The encoding was fine, but // json_last_error gets the error from the json_decode before throw new Exception("encoding went wrong!"); } echo "All is fine"; Expected result: ---------------- json_last_error() gives the error for the last call, regardless of the flag. Actual result: -------------- json_last_error() give the error for the previous that did not have JSON_THROW_ON_ERROR set.