ID: 45989 Updated by: [EMAIL PROTECTED] Reported By: steven at acko dot net -Status: Open +Status: Bogus Bug Type: JSON related Operating System: Mac OS X PHP Version: 5.2.6 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php . Previous Comments: ------------------------------------------------------------------------ [2008-09-04 00:32:20] steven at acko dot net 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 this bug report at http://bugs.php.net/?id=45989&edit=1