php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80553 `json_decode()`-documentation has false information
Submitted: 2020-12-26 19:53 UTC Modified: 2020-12-26 21:32 UTC
From: lars at lquenti dot de Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 7.3.25 OS: Arch
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lars at lquenti dot de
New email:
PHP Version: OS:

 

 [2020-12-26 19:53 UTC] lars at lquenti dot de
Description:
------------
The documentation https://www.php.net/manual/en/function.json-decode.php mentions the following:

Values true, false and null are returned as true, false and null respectively.

As shown in the test script, `json_decode(false)` returns `null` instead of false.
`json_decode(true)` works as expected.

Test script:
---------------
<?php echo is_null(json_decode(false)) ?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-26 19:58 UTC] dharman@php.net
-Status: Open +Status: Not a bug
 [2020-12-26 19:58 UTC] dharman@php.net
I don't see a problem with the documentation. It says: "null is returned if the json cannot be decoded". You are passing invalid value (false) so the function fails. When it fails it returns NULL as described. 

I believe you misunderstood that other note. Consider the correct example:

<?php var_dump(json_decode("false"));

This will return native PHP value false. The output is:

bool(false)

Please note that the first parameter of json_decode is string. It does not accept any other value, which means booleans are not valid and the function will fail.
 [2020-12-26 21:32 UTC] lars at lquenti dot de
I'm so sorry, you are right... Again, I'm sorry for the inconvenience.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 06 21:01:29 2024 UTC