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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Apr 19 23:01:28 2024 UTC