Skip to content

Commit 79a36ff

Browse files
committed
Fixed bug #79477
Make sure to deindirect properties when creating array.
1 parent c4cdf1a commit 79a36ff

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Fixed bug #79434 (PHP 7.3 and PHP-7.4 crash with NULL-pointer dereference
77
on !CS constant). (Nikita)
8+
. Fixed bug #79477 (casting object into array creates references). (Nikita)
89

910
- DOM:
1011
. Fixed bug #78221 (DOMNode::normalize() doesn't remove empty text nodes).

Zend/tests/bug79477.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #79477: casting object into array creates references
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public $prop = 'default value';
8+
}
9+
10+
$obj = new Test;
11+
$obj->{1} = null;
12+
13+
$arr = (array) $obj;
14+
$arr['prop'] = 'new value';
15+
16+
echo $obj->prop, "\n";
17+
18+
?>
19+
--EXPECT--
20+
default value

Zend/zend_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,7 @@ ZEND_API HashTable* ZEND_FASTCALL zend_proptable_to_symtable(HashTable *ht, zend
27222722
{
27232723
HashTable *new_ht = zend_new_array(zend_hash_num_elements(ht));
27242724

2725-
ZEND_HASH_FOREACH_KEY_VAL(ht, num_key, str_key, zv) {
2725+
ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num_key, str_key, zv) {
27262726
do {
27272727
if (Z_OPT_REFCOUNTED_P(zv)) {
27282728
if (Z_ISREF_P(zv) && Z_REFCOUNT_P(zv) == 1) {

0 commit comments

Comments
 (0)