Doc #65907 [NEW]: json_decode returns NULL if input is NULL

From: Date: Wed, 16 Oct 2013 00:36:13 +0000
Subject: Doc #65907 [NEW]: json_decode returns NULL if input is NULL
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10501@lists.php.net to get a copy of this message
From: bsasser at sindtech dot net Operating system: Linux/GNU PHP version: Irrelevant Package: JSON related Bug Type: Documentation Problem Bug description:json_decode returns NULL if input is NULL 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 -- Edit bug report at https://bugs.php.net/bug.php?id=65907&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65907&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=65907&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65907&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65907&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65907&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65907&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65907&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65907&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65907&r=support Expected behavior: https://bugs.php.net/fix.php?id=65907&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65907&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65907&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65907&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65907&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65907&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65907&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65907&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65907&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65907&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65907&r=mysqlcfg

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