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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 - 26 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Wed Apr 24 09:01:28 2024 UTC