com php-src: Fix bug #71835 (json_encode sometimes inco rrectly detects recursion with JsonSerializable): NEWS Zend/zend_builtin_functions.c
ext/json/tests/ bug71835.phpt

From: Date: Sun, 20 Mar 2016 15:56:27 +0000
Subject: com php-src: Fix bug #71835 (json_encode sometimes inco rrectly detects recursion with JsonSerializable): NEWS Zend/zend_builtin_functions.c
ext/json/tests/ bug71835.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-91436@lists.php.net to get a copy of this message
Commit: 7e069daa89f05c1fa4127b2cedfd5586dbfc810e Author: Jakub Zelenka <bukka@php.net> Sun, 20 Mar 2016 15:53:57 +0000 Parents: a175aa9dcaed5e295d015ff73c663e06c2335155 Branches: PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7e069daa89f05c1fa4127b2cedfd5586dbfc810e Log: Fix bug #71835 (json_encode sometimes incorrectly detects recursion with JsonSerializable) Bugs: https://bugs.php.net/71835 Changed paths: M NEWS M Zend/zend_builtin_functions.c A ext/json/tests/bug71835.phpt Diff: diff --git a/NEWS b/NEWS index 0cccc6a..63b405f 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ PHP NEWS . Fixed bug #69659 (ArrayAccess, isset() and the offsetExists method). (Nikita) +- JSON: + . Fixed bug #71835 (json_encode sometimes incorrectly detects recursion + with JsonSerializable). (Jakub Zelenka) + - ODBC: . Fixed bug #63171 (Script hangs after max_execution_time). (Remi) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 231424f..a576455 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1183,7 +1183,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 0000000...bbca198 --- /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) "[[[]]]"

« previous php.cvs (#91436) next »