LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: steven@acko.net Date: Tue Oct 7 01:49:55 2008 Subject: note 86181 added to function.json-decode
json_decode()'s handling of invalid JSON is very flaky, and it is very hard to reliably determine if the decoding succeeded or not. Observe the following examples, none of which contain valid JSON:
The following each returns NULL, as you might expect:
var_dump(json_decode('[')); // unmatched bracket
var_dump(json_decode('{')); // unmatched brace
var_dump(json_decode('{}}')); // unmatched brace
var_dump(json_decode('{error error}')); // invalid object key/value
notation
var_dump(json_decode('["\"]')); // unclosed string
var_dump(json_decode('[" \x "]')); // invalid escape code
Yet the following each returns the literal string you passed to it:
var_dump(json_decode(' [')); // unmatched bracket
var_dump(json_decode(' {')); // unmatched brace
var_dump(json_decode(' {}}')); // unmatched brace
var_dump(json_decode(' {error error}')); // invalid object key/value notation
var_dump(json_decode('"\"')); // unclosed string
var_dump(json_decode('" \x "')); // invalid escape code
(this is on PHP 5.2.6)
Reported as a bug, but oddly enough, it was closed as not a bug:
http://bugs.php.net/bug.php?id=45989
----
Server IP: 66.207.199.35
Probable Submitter: 216.19.186.195
----
Manual Page -- http://www.php.net/manual/en/function.json-decode.php
Edit -- https://master.php.net/note/edit/86181
Del: integrated -- https://master.php.net/note/delete/86181/integrated
Del: useless -- https://master.php.net/note/delete/86181/useless
Del: bad code -- https://master.php.net/note/delete/86181/bad+code
Del: spam -- https://master.php.net/note/delete/86181/spam
Del: non-english -- https://master.php.net/note/delete/86181/non-english
Del: in docs -- https://master.php.net/note/delete/86181/in+docs
Del: other reasons-- https://master.php.net/note/delete/86181
Reject -- https://master.php.net/note/reject/86181
Search -- https://master.php.net/manage/user-notes.php
| Navigate in group php.notes at sever news.php.net | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by PHP Developer
Powered By PHP Consultants |