Doc #65907 [Opn->Fbk]: json_decode returns NULL if input is NULL
| From: | yohgaki@php.net | Date: | Fri, 01 Nov 2013 05:20:11 +0000 |
| Subject: | Doc #65907 [Opn->Fbk]: json_decode returns NULL if input is NULL | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-10576@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65907&edit=1
ID: 65907
Updated by: yohgaki@php.net
Reported by: bsasser at sindtech dot net
Summary: json_decode returns NULL if input is NULL
-Status: Open
+Status: Feedback
Type: Documentation Problem
Package: JSON related
Operating System: Linux/GNU
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I guess you are using Debian or Ubuntu aren't you?
IIRC, there is similar bug reports from these OS users.
BTW, my PHP from Fedora 19 returns null/true/false as expected.
Previous Comments:
------------------------------------------------------------------------
[2013-10-16 00:36:13] bsasser at sindtech dot net
Description:
------------
---
From manual page: http://www.php.net/function.json-encode#refsect1-function.json-encode-returnvalues
---
It states "Return Values
Returns a JSON encoded string on success or FALSE on failure."
Except, when input is NULL, it returns NULL, not FALSE.
Ref. bug #49588 where the following comment is made:
" [2012-07-02 16:58 UTC] gudjonj at gmail dot com
To return null if encoding is incorrect makes no sense."
This is not a duplicate - this is expressly for NULL as input (all other bug reports involve special
characters/local issues). However, the comment is correct - returning NULL [for any reason] if
encoding makes no sense.
Test script:
---------------
$a = NULL;
$b = FALSE;
$c = array("Hello","world!");
var_dump(json_encode($a));
var_dump(json_encode($b));
var_dump(json_encode($c));
Expected result:
----------------
When encoding NULL, FALSE is the expected output (not just because it makes sense, but because the
documentation says so ;-) ).
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65907&edit=1