php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78515 JSON_THROW_ON_ERROR doesn't throw an exception
Submitted: 2019-09-09 10:13 UTC Modified: 2019-09-09 10:26 UTC
From: nick dot kdevil at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 7.3.9 OS: Linux
Private report: No CVE-ID: None
 [2019-09-09 10:13 UTC] nick dot kdevil at gmail dot com
Description:
------------
I was under the impression, that if i have a json_last_error, that if the flag JSON_THROW_ON_ERROR is set, i will get an exception. In the example below json_last_error would return 4, but no exception is thrown.

Test script:
---------------
json_decode('test',true,JSON_THROW_ON_ERROR);

Expected result:
----------------
The appropriate exception is thrown

Actual result:
--------------
NULL is being returned

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-09 10:15 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-09-09 10:15 UTC] nikic@php.net
Please see the function signature at https://www.php.net/json_decode. You are passing the flag to the $depth parameter, not the $options parameter.
 [2019-09-09 10:18 UTC] nick dot kdevil at gmail dot com
the embarassment is real :/
thx nikic
 [2019-09-09 10:26 UTC] nick dot kdevil at gmail dot com
@nikic while this is totally due to my own stupidity, i see where i went wrong

while encode has options first, then depth
decode has depth first, then options

maybe it would be worth aligning this?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC