diff options
| -rw-r--r-- | Zend/zend_builtin_functions.c | 2 | ||||
| -rw-r--r-- | ext/json/tests/bug71835.phpt | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 0b48df48bf..a35c519c03 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1249,7 +1249,7 @@ ZEND_FUNCTION(get_object_vars) zobj = Z_OBJ_P(obj); - if (!zobj->ce->default_properties_count && properties == zobj->properties) { + if (!zobj->ce->default_properties_count && properties == zobj->properties && !ZEND_HASH_GET_APPLY_COUNT(properties)) { /* fast copy */ if (EXPECTED(zobj->handlers == &std_object_handlers)) { if (EXPECTED(!(GC_FLAGS(properties) & IS_ARRAY_IMMUTABLE))) { diff --git a/ext/json/tests/bug71835.phpt b/ext/json/tests/bug71835.phpt new file mode 100644 index 0000000000..bbca19829b --- /dev/null +++ b/ext/json/tests/bug71835.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #71835 (json_encode sometimes incorrectly detects recursion with JsonSerializable) +--SKIPIF-- +<?php if (!extension_loaded("json")) print "skip"; ?> +--FILE-- +<?php +class SomeClass implements JsonSerializable { + public function jsonSerialize() { + return [get_object_vars($this)]; + } +} +$class = new SomeClass; +$arr = [$class]; +var_dump(json_encode($arr)); +?> +--EXPECT-- +string(6) "[[[]]]" |
