|  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 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:
Solve the problem:
40 + 15 = ?
Subscribe to this entry?

 [2020-12-26 19:53 UTC] lars at lquenti dot de
The documentation 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)) ?>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-26 19:58 UTC]
-Status: Open +Status: Not a bug
 [2020-12-26 19:58 UTC]
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:


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-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 09:03:37 2021 UTC