From: Nikita Popov Date: Mon, 8 Oct 2018 11:14:54 +0000 (+0200) Subject: Fix ref ID handling when serializing $GLOBALS X-Git-Tag: php-7.3.0RC3~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d982bbe175b6f4487683f538f2dc8aca4aef4a6b;p=php Fix ref ID handling when serializing $GLOBALS This was already broken previously, but in PHP 7.3 stricter validation during unserialization made this into an error. --- diff --git a/ext/standard/tests/serialize/serialize_globals_var_refs.phpt b/ext/standard/tests/serialize/serialize_globals_var_refs.phpt new file mode 100644 index 0000000000..3f03cc2a21 --- /dev/null +++ b/ext/standard/tests/serialize/serialize_globals_var_refs.phpt @@ -0,0 +1,22 @@ +--TEST-- +Reference IDs should be correctly generated when $GLOBALS is serialized +--FILE-- +obj = $obj; +$s = serialize($GLOBALS); +$globals = unserialize($s); +var_dump($obj); +var_dump($obj2); + +?> +--EXPECT-- +object(stdClass)#1 (0) { +} +object(stdClass)#2 (1) { + ["obj"]=> + object(stdClass)#1 (0) { + } +} diff --git a/ext/standard/var.c b/ext/standard/var.c index e4c7932868..77b290a6cc 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -959,9 +959,9 @@ again: /* we should still add element even if it's not OK, * since we already wrote the length of the array before */ if (Z_TYPE_P(data) == IS_ARRAY) { - if (Z_TYPE_P(data) == IS_ARRAY - && (UNEXPECTED(Z_IS_RECURSIVE_P(data)) - || UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc)))) { + if (UNEXPECTED(Z_IS_RECURSIVE_P(data)) + || UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc))) { + php_add_var_hash(var_hash, struc); smart_str_appendl(buf, "N;", 2); } else { if (Z_REFCOUNTED_P(data)) {