Doc #80553 [Opn->Nab]: `json_decode()`-documentation has false information
Edit report at https://bugs.php.net/bug.php?id=80553&edit=1
ID: 80553
Updated by: dharman@php.net
Reported by: lars at lquenti dot de
Summary: json_decode()-documentation has false information
-Status: Open
+Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
Operating System: Arch
PHP Version: 7.3.25
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2020-12-26 19:53:05] 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)) ?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80553&edit=1
Thread (3 messages)