Skip to content

Commit 59a5f89

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Undef slot before destroying in unset_property
2 parents 339ce94 + 567e53e commit 59a5f89

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

Zend/tests/unset_prop_recursion.phpt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--TEST--
2+
Unset property where unset will recursively access property again
3+
--FILE--
4+
<?php
5+
class Node {
6+
public $parent = null;
7+
public $children = [];
8+
function insert(Node $node) {
9+
$node->parent = $this;
10+
$this->children[] = $node;
11+
}
12+
function __destruct() {
13+
var_dump($this);
14+
unset($this->children);
15+
}
16+
}
17+
18+
$a = new Node;
19+
$a->insert(new Node);
20+
$a->insert(new Node);
21+
?>
22+
--EXPECT--
23+
object(Node)#1 (2) {
24+
["parent"]=>
25+
NULL
26+
["children"]=>
27+
array(2) {
28+
[0]=>
29+
object(Node)#2 (2) {
30+
["parent"]=>
31+
*RECURSION*
32+
["children"]=>
33+
array(0) {
34+
}
35+
}
36+
[1]=>
37+
object(Node)#3 (2) {
38+
["parent"]=>
39+
*RECURSION*
40+
["children"]=>
41+
array(0) {
42+
}
43+
}
44+
}
45+
}
46+
object(Node)#2 (2) {
47+
["parent"]=>
48+
object(Node)#1 (2) {
49+
["parent"]=>
50+
NULL
51+
}
52+
["children"]=>
53+
array(0) {
54+
}
55+
}
56+
object(Node)#3 (2) {
57+
["parent"]=>
58+
object(Node)#1 (2) {
59+
["parent"]=>
60+
NULL
61+
}
62+
["children"]=>
63+
array(0) {
64+
}
65+
}

Zend/zend_object_handlers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,10 @@ ZEND_API void zend_std_unset_property(zend_object *zobj, zend_string *name, void
10091009
ZEND_REF_DEL_TYPE_SOURCE(Z_REF_P(slot), prop_info);
10101010
}
10111011
}
1012-
zval_ptr_dtor(slot);
1012+
zval tmp;
1013+
ZVAL_COPY_VALUE(&tmp, slot);
10131014
ZVAL_UNDEF(slot);
1015+
zval_ptr_dtor(&tmp);
10141016
if (zobj->properties) {
10151017
HT_FLAGS(zobj->properties) |= HASH_FLAG_HAS_EMPTY_IND;
10161018
}

0 commit comments

Comments
 (0)