Skip to content

Commit d982bbe

Browse files
committed
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.
1 parent c5df679 commit d982bbe

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Reference IDs should be correctly generated when $GLOBALS is serialized
3+
--FILE--
4+
<?php
5+
6+
$obj = new stdClass;
7+
$obj2 = new stdClass;
8+
$obj2->obj = $obj;
9+
$s = serialize($GLOBALS);
10+
$globals = unserialize($s);
11+
var_dump($obj);
12+
var_dump($obj2);
13+
14+
?>
15+
--EXPECT--
16+
object(stdClass)#1 (0) {
17+
}
18+
object(stdClass)#2 (1) {
19+
["obj"]=>
20+
object(stdClass)#1 (0) {
21+
}
22+
}

ext/standard/var.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,9 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
959959
/* we should still add element even if it's not OK,
960960
* since we already wrote the length of the array before */
961961
if (Z_TYPE_P(data) == IS_ARRAY) {
962-
if (Z_TYPE_P(data) == IS_ARRAY
963-
&& (UNEXPECTED(Z_IS_RECURSIVE_P(data))
964-
|| UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc)))) {
962+
if (UNEXPECTED(Z_IS_RECURSIVE_P(data))
963+
|| UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc))) {
964+
php_add_var_hash(var_hash, struc);
965965
smart_str_appendl(buf, "N;", 2);
966966
} else {
967967
if (Z_REFCOUNTED_P(data)) {

0 commit comments

Comments
 (0)