Skip to content

Commit 34208bf

Browse files
committed
Merge branch 'PHP-8.1'
2 parents cb3bc65 + 96e3a9d commit 34208bf

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.0alpha2
44

5+
- Core:
6+
. Fixed bug GH-8655 (Casting an object to array does not unwrap refcount=1
7+
references). (Nicolas Grekas)
58

69
09 Jun 2022, PHP 8.2.0alpha1
710

Zend/tests/bugGH-8655.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug GH-8655 (zval reference is not released when targetting a declared property)
3+
--FILE--
4+
<?php
5+
class Foo
6+
{
7+
public $foo;
8+
}
9+
10+
function hydrate($properties, $object)
11+
{
12+
foreach ($properties as $name => &$value) {
13+
$object->$name = &$value;
14+
}
15+
};
16+
17+
$object = new Foo;
18+
19+
hydrate(['foo' => 123], $object);
20+
21+
$arrayCast = (array) $object;
22+
23+
$object->foo = 234;
24+
var_dump(ReflectionReference::fromArrayElement($arrayCast, 'foo'));
25+
echo $arrayCast['foo'];
26+
?>
27+
--EXPECT--
28+
NULL
29+
123

Zend/zend_object_handlers.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj) /*
111111
continue;
112112
}
113113

114+
if (Z_ISREF_P(prop) && Z_REFCOUNT_P(prop) == 1) {
115+
prop = Z_REFVAL_P(prop);
116+
}
117+
114118
Z_TRY_ADDREF_P(prop);
115119
_zend_hash_append(ht, prop_info->name, prop);
116120
}

0 commit comments

Comments
 (0)