|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bsasser at sindtech dot net
New email:
PHP Version: OS:


 [2013-10-16 00:36 UTC] bsasser at sindtech dot net
From manual page:
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!");




Expected result:
When encoding NULL, FALSE is the expected output (not just because it makes sense, but because the documentation says so ;-)   ).

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-01 05:20 UTC]
-Status: Open +Status: Feedback
 [2013-11-01 05:20 UTC]
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-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 29 01:03:36 2021 UTC