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

From: Date: Sun, 27 Nov 2011 08:02:26 +0000
Subject: Doc #60394 [Com]: Return value for json_encode() on failure not listed
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7479@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 Comment by: irker@php.net 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: 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) Previous Comments: ------------------------------------------------------------------------ [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 (#7479) next »