|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)) ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 03:00:02 2025 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: 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.