From 84fe2cc890e49f40bac7c3ba74b3cfc6dc4cef2f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 23 Jun 2012 20:46:27 +0200 Subject: Improve json_encode error handling json_encode() now returns bool(false) for all possible errors, throws the respective warning and also sets the respective json_last_error() error code. Three new error codes have been added: * JSON_ERROR_RECURSION * JSON_ERROR_INF_OR_NAN * JSON_ERROR_UNSUPPORTED_TYPE To get a partial JSON output instead of bool(false) the option JSON_PARTIAL_OUTPUT_ON_ERROR can be specified. In this case the invalid segments will be replaced either by null (for recursion, unsupported type and invalid JSON) or 0 (for Inf and NaN). The warning for invalid UTF-8 stays intact and is thrown also with display_errors = On. If this behavior is undesired this can be remedied later. --- ext/json/tests/json_encode_basic.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/json/tests/json_encode_basic.phpt') diff --git a/ext/json/tests/json_encode_basic.phpt b/ext/json/tests/json_encode_basic.phpt index 003fcd44c6..7ee68c58ca 100644 --- a/ext/json/tests/json_encode_basic.phpt +++ b/ext/json/tests/json_encode_basic.phpt @@ -151,8 +151,8 @@ string(4) "null" string(4) "null" -- Iteration 26 -- -Warning: json_encode(): type is unsupported, encoded as null in %s on line %d -string(4) "null" +Warning: json_encode(): type is unsupported in %s on line %d +bool(false) -- Iteration 27 -- string(82) "{"MyInt":99,"MyFloat":123.45,"MyBool":true,"MyNull":null,"MyString":"Hello World"}" ===Done=== -- cgit v1.2.1