php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65907 json_decode returns NULL if input is NULL
Submitted: 2013-10-16 00:36 UTC Modified: 2014-12-30 10:42 UTC
From: bsasser at sindtech dot net Assigned:
Status: No Feedback Package: JSON related
PHP Version: Irrelevant OS: Linux/GNU
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-10-16 00:36 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-01 05:20 UTC] yohgaki@php.net
-Status: Open +Status: Feedback
 [2013-11-01 05:20 UTC] yohgaki@php.net
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.
 [2014-12-30 10:42 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 05:01:29 2024 UTC