Doc #80553 [Nab]: `json_decode()`-documentation has false information

From: Date: Sat, 26 Dec 2020 21:32:36 +0000
Subject: Doc #80553 [Nab]: `json_decode()`-documentation has false information
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18320@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80553&edit=1

 ID:                 80553
 User updated by:    lars at lquenti dot de
 Reported by:        lars at lquenti dot de
 Summary:            json_decode()-documentation has false information
 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'm so sorry, you are right... Again, I'm sorry for the inconvenience.


Previous Comments:
------------------------------------------------------------------------
[2020-12-26 19:58:48] 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 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)

« previous php.doc.bugs (#18320) next »