summaryrefslogtreecommitdiff
path: root/ext/json/json_encoder.c
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2016-04-22 21:41:44 -0700
committerXinchen Hui <laruence@gmail.com>2016-04-22 21:41:44 -0700
commit589d0e0f187ff82f90110057f624c958f0d3ec86 (patch)
treeb12313d443ae59eb85827f8f05975e16c7a53ea7 /ext/json/json_encoder.c
parent9eb7c8cd3b202ff77f1442f5a5d3107bd7fc3a18 (diff)
downloadphp-git-589d0e0f187ff82f90110057f624c958f0d3ec86.tar.gz
Fixed bug #72069 (Behavior \JsonSerializable different from json_encode)
Diffstat (limited to 'ext/json/json_encoder.c')
-rw-r--r--ext/json/json_encoder.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c
index 6c2f377034..ae9e086fc0 100644
--- a/ext/json/json_encoder.c
+++ b/ext/json/json_encoder.c
@@ -448,6 +448,7 @@ static void php_json_encode_serializable_object(smart_str *buf, zval *val, int o
zend_class_entry *ce = Z_OBJCE_P(val);
zval retval, fname;
HashTable* myht;
+ int origin_error_code;
if (Z_TYPE_P(val) == IS_ARRAY) {
myht = Z_ARRVAL_P(val);
@@ -461,8 +462,10 @@ static void php_json_encode_serializable_object(smart_str *buf, zval *val, int o
return;
}
+
ZVAL_STRING(&fname, "jsonSerialize");
+ origin_error_code = JSON_G(error_code);
if (FAILURE == call_user_function_ex(EG(function_table), val, &fname, &retval, 0, NULL, 1, NULL) || Z_TYPE(retval) == IS_UNDEF) {
zend_throw_exception_ex(NULL, 0, "Failed calling %s::jsonSerialize()", ZSTR_VAL(ce->name));
smart_str_appendl(buf, "null", sizeof("null") - 1);
@@ -470,6 +473,7 @@ static void php_json_encode_serializable_object(smart_str *buf, zval *val, int o
return;
}
+ JSON_G(error_code) = origin_error_code;
if (EG(exception)) {
/* Error already raised */
zval_ptr_dtor(&retval);