Bug #77997 [Opn]: json_last_error should work even if JSON_THROW_ON_ERROR
| From: | cmb@php.net | Date: | Thu, 09 May 2019 16:13:45 +0000 |
| Subject: | Bug #77997 [Opn]: json_last_error should work even if JSON_THROW_ON_ERROR | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220801@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77997&edit=1
ID: 77997
Updated by: cmb@php.net
Reported by: danack@php.net
Summary: json_last_error should work even if
JSON_THROW_ON_ERROR
Status: Open
Type: Bug
Package: JSON related
PHP Version: 7.3.5
Block user comment: N
Private report: N
New Comment:
This behavior is explicitly defined by the respective RFC[1]:
| When passed this flag, the error behaviour of these functions is
| changed. The global error state is left untouched, [â¦]
Changes to this behavior should at the very least be discussed on
the internals mailing list.
[1] <https://wiki.php.net/rfc/json_throw_on_error#proposal
Previous Comments:
------------------------------------------------------------------------
[2019-05-09 15:53:27] danack@php.net
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.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77997&edit=1