Doc #60394 [Bgs]: Return value for json_encode() on failure not listed

From: Date: Sun, 27 Nov 2011 09:02:06 +0000
Subject: Doc #60394 [Bgs]: Return value for json_encode() on failure not listed
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7480@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60394&edit=1 ID: 60394 User updated by: papersnowman at gmail dot com Reported by: papersnowman at gmail dot com Summary: Return value for json_encode() on failure not listed Status: Bogus Type: Documentation Problem Package: Documentation problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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? Previous Comments: ------------------------------------------------------------------------ [2011-11-27 08:02:26] irker@php.net 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 03:02:18] frozenfire@php.net 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 string. 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-26 20:25:11] papersnowman at gmail dot com Description: ------------ --- From manual page: http://www.php.net/function.json-encode#refsect1-function.json- encode-returnvalues --- Documentation shows expected return value on success, but not failure. I would presume === false, but it is nice to be able to confirm. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60394&edit=1

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