Edit report at https://bugs.php.net/bug.php?id=64874&edit=1
ID: 64874 Comment by: cmbecker69 at gmx dot de Reported by: chrivers at iversen-net dot dk Summary: json_decode handles whitespace and case-sensitivity incorrectly Status: Open Type: Bug Package: JSON related Operating System: All PHP Version: 5.4.15 Block user comment: N Private report: N New Comment: RFC 4627[1] also states in section 2: | A JSON text is a serialized object or array. | | JSON-text = object / array According to that definition the $json argument of examples 1-3 is not a valid JSON-text. Furthermore: json_decode('true '); var_dump(json_last_error() === JSON_ERROR_SYNTAX); prints: bool(true) So the returned NULL is actually correct according to the documentation. [1] <http://www.ietf.org/rfc/rfc4627.txt> Previous Comments: ------------------------------------------------------------------------ [2013-05-17 21:48:29] chrivers at iversen-net dot dk Description: ------------ There are 2 problems with the json_decode function. 1) It only sometimes disregards whitespace The RFC clearly says: """Insignificant whitespace is allowed before or after any of the six structural characters.""" 2) It only sometimes enforces lowercase-ness of identifiers The RFC clearly says: """The literal names MUST be lowercase. No other literal names are allowed.""" The test script demonstrates this Test script: --------------- <? function json_cmp($x, $y) { print var_dump(json_decode($x) === $y); } // works json_cmp("true", true); // fails - is actually true json_cmp("tRue", NULL); // fails - is actually NULL json_cmp("true ", true); // works json_cmp("[true ] ", array(true)); // works, even though the non-array version fails json_cmp("[tRue]", NULL); ?> Expected result: ---------------- true * 5 Actual result: -------------- bool(true) bool(false) bool(false) bool(true) bool(true) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64874&edit=1