diff --git a/ext/json/json_encoder.c b/ext/json/json_encoder.c index adb53598326bd..d93e2a385d6fc 100644 --- a/ext/json/json_encoder.c +++ b/ext/json/json_encoder.c @@ -534,12 +534,12 @@ static zend_result php_json_escape_string( static zend_result php_json_encode_serializable_object(smart_str *buf, zval *val, int options, php_json_encoder *encoder) /* {{{ */ { + zend_object *obj = Z_OBJ_P(val); zend_class_entry *ce = Z_OBJCE_P(val); - HashTable* myht = Z_OBJPROP_P(val); zval retval, fname; zend_result return_code; - if (myht && GC_IS_RECURSIVE(myht)) { + if (GC_IS_RECURSIVE(obj)) { encoder->error_code = PHP_JSON_ERROR_RECURSION; if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); @@ -547,7 +547,7 @@ static zend_result php_json_encode_serializable_object(smart_str *buf, zval *val return FAILURE; } - PHP_JSON_HASH_PROTECT_RECURSION(myht); + GC_PROTECT_RECURSION(obj); ZVAL_STRING(&fname, "jsonSerialize"); @@ -560,7 +560,7 @@ static zend_result php_json_encode_serializable_object(smart_str *buf, zval *val if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); } - PHP_JSON_HASH_UNPROTECT_RECURSION(myht); + GC_UNPROTECT_RECURSION(obj); return FAILURE; } @@ -572,19 +572,19 @@ static zend_result php_json_encode_serializable_object(smart_str *buf, zval *val if (options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR) { smart_str_appendl(buf, "null", 4); } - PHP_JSON_HASH_UNPROTECT_RECURSION(myht); + GC_UNPROTECT_RECURSION(obj); return FAILURE; } if ((Z_TYPE(retval) == IS_OBJECT) && (Z_OBJ(retval) == Z_OBJ_P(val))) { /* Handle the case where jsonSerialize does: return $this; by going straight to encode array */ - PHP_JSON_HASH_UNPROTECT_RECURSION(myht); + GC_UNPROTECT_RECURSION(obj); return_code = php_json_encode_array(buf, &retval, options, encoder); } else { /* All other types, encode as normal */ return_code = php_json_encode_zval(buf, &retval, options, encoder); - PHP_JSON_HASH_UNPROTECT_RECURSION(myht); + GC_UNPROTECT_RECURSION(obj); } zval_ptr_dtor(&retval); diff --git a/ext/json/tests/bug77843.phpt b/ext/json/tests/bug77843.phpt index 2709612659c61..39180e95d2623 100644 --- a/ext/json/tests/bug77843.phpt +++ b/ext/json/tests/bug77843.phpt @@ -18,8 +18,5 @@ var_dump(json_encode([&$arr])); ?> --EXPECT-- -object(X)#1 (1) { - ["prop"]=> - string(5) "value" -} +*RECURSION* string(20) "[[{"prop":"value"}]]" diff --git a/ext/standard/tests/class_object/get_object_vars_variation_004.phpt b/ext/standard/tests/class_object/get_object_vars_variation_004.phpt index 84827134c1b18..e89b18c02d9a2 100644 --- a/ext/standard/tests/class_object/get_object_vars_variation_004.phpt +++ b/ext/standard/tests/class_object/get_object_vars_variation_004.phpt @@ -43,6 +43,5 @@ array(4) { [12]=> int(6) ["test"]=> - object(JsonSerializable@anonymous)#2 (0) { - } + *RECURSION* }