Make sure to deindirect properties when creating array.
This commit is contained in:
Nikita Popov 2020-04-15 11:20:33 +02:00
parent c4cdf1ae12
commit 79a36ff7f3
3 changed files with 22 additions and 1 deletions

1
NEWS
View File

@ -5,6 +5,7 @@ PHP NEWS
- Core:
. Fixed bug #79434 (PHP 7.3 and PHP-7.4 crash with NULL-pointer dereference
on !CS constant). (Nikita)
. Fixed bug #79477 (casting object into array creates references). (Nikita)
- DOM:
. Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes).

20
Zend/tests/bug79477.phpt Normal file
View File

@ -0,0 +1,20 @@
--TEST--
Bug #79477: casting object into array creates references
--FILE--
<?php
class Test {
public $prop = 'default value';
}
$obj = new Test;
$obj->{1} = null;
$arr = (array) $obj;
$arr['prop'] = 'new value';
echo $obj->prop, "\n";
?>
--EXPECT--
default value

View File

@ -2722,7 +2722,7 @@ convert:
{
HashTable *new_ht = zend_new_array(zend_hash_num_elements(ht));
ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, zv) {
ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, str_key, zv) {
do {
if (Z_OPT_REFCOUNTED_P(zv)) {
if (Z_ISREF_P(zv) && Z_REFCOUNT_P(zv) == 1) {