Skip to content

Commit

Permalink
Merge branch 'PHP-8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Jun 9, 2022
2 parents cb3bc65 + 96e3a9d commit 34208bf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.2.0alpha2

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

09 Jun 2022, PHP 8.2.0alpha1

Expand Down
29 changes: 29 additions & 0 deletions Zend/tests/bugGH-8655.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Bug GH-8655 (zval reference is not released when targetting a declared property)
--FILE--
<?php
class Foo
{
public $foo;
}

function hydrate($properties, $object)
{
foreach ($properties as $name => &$value) {
$object->$name = &$value;
}
};

$object = new Foo;

hydrate(['foo' => 123], $object);

$arrayCast = (array) $object;

$object->foo = 234;
var_dump(ReflectionReference::fromArrayElement($arrayCast, 'foo'));
echo $arrayCast['foo'];
?>
--EXPECT--
NULL
123
4 changes: 4 additions & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj) /*
continue;
}

if (Z_ISREF_P(prop) && Z_REFCOUNT_P(prop) == 1) {
prop = Z_REFVAL_P(prop);
}

Z_TRY_ADDREF_P(prop);
_zend_hash_append(ht, prop_info->name, prop);
}
Expand Down

0 comments on commit 34208bf

Please sign in to comment.