From: steven at acko dot net Operating system: Mac OS X PHP version: 5.2.6 PHP Bug Type: JSON related Bug description: json_decode() passes through certain invalid JSON strings
Description: ------------ When json_decode() is given certain invalid JSON strings, it will return the literal string as the result, rather than returning NULL. Note: in #38680, the decision was made to allow json_decode() to accept literal basic types (strings, ints, ...) even though this is not allowed by RFC 4627 (which only allows objects/arrays). This bug report is different because even under the PHP interpretation of JSON, these strings can not be considered valid, and trivial variations on them do in fact throw an error as expected. (The non-standard behaviour introduced in #38680 is not documented at all by the way, which is kind of ironic given the numerous issues that have 'go read the spec' as the answer) Reproduce code: --------------- var_dump(json_decode("'invalid json'")); var_dump(json_decode('invalid json')); var_dump(json_decode(' {')); var_dump(json_decode(' [')); Expected result: ---------------- NULL NULL NULL NULL Actual result: -------------- string(14) "'invalid json'" string(12) "invalid json" string(2) " {" string(2) " [" -- Edit bug report at http://bugs.php.net/?id=45989&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45989&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45989&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45989&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45989&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45989&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45989&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45989&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45989&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45989&r=support Expected behavior: http://bugs.php.net/fix.php?id=45989&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45989&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45989&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45989&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45989&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45989&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45989&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45989&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45989&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45989&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45989&r=mysqlcfg