|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60394 Return value for json_encode() on failure not listed
Submitted: 2011-11-26 20:25 UTC Modified: 2011-11-27 09:02 UTC
From: papersnowman at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
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: papersnowman at gmail dot com
New email:
PHP Version: OS:


 [2011-11-26 20:25 UTC] papersnowman at gmail dot com
From manual page:
Documentation shows expected return value on success, but not failure. I would 
presume === false, but it is nice to be able to confirm.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-27 03:02 UTC]
-Status: Open +Status: Bogus
 [2011-11-27 03:02 UTC]
This function is, surprisingly, properly documented. I was working on resolving 
this bug, when I checked the sources for the function, and found that there is 
no non-error situation where the function will return anything but an encoded 

The reason for this is all types can be encoded, including null. There are no 
values which you could pass to json_encode that would not result in a string 
being returned. The only way for it to fail is for you to not pass it an 
incorrect number of parameters, or some other error in syntax.
 [2011-11-27 08:02 UTC]
Not all types can encode. For example: Resource.

php -r "var_dump(json_encode(fopen('/tmp/temp', 'w+')));"
PHP Warning:  json_encode(): type is unsupported, encoded as null in Command line 
code on line 1
string(4) "null"

But, I agree that it anyway returns a string ("null" string)
 [2011-11-27 09:02 UTC] papersnowman at gmail dot com
That being the case, would it be worth modifying the "Return Values" section in the documentation from "Returns a JSON encoded string on success.", since there seems to be no failure case as "on success" seems to imply? something like "Returns a JSON encoded string in all cases" or possibly something mentioning the null return case?
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Apr 17 21:01:27 2021 UTC