Skip to content

Commit 10a38b7

Browse files
committed
Fix incorrect clone of trait method during inheritance
1 parent eb8ba60 commit 10a38b7

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Zend/tests/gh16198_2.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-16198: Usage of super in cloned trait method
3+
--FILE--
4+
<?php
5+
6+
trait T {
7+
public function __destruct() {
8+
parent::__destruct();
9+
}
10+
}
11+
12+
class P {
13+
public function __destruct() {
14+
var_dump(__METHOD__);
15+
}
16+
}
17+
18+
class C extends P {
19+
use T;
20+
}
21+
22+
$c = new C();
23+
unset($c);
24+
25+
?>
26+
--EXPECT--
27+
string(13) "P::__destruct"

Zend/zend_inheritance.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,10 @@ static inheritance_status do_inheritance_check_on_method(
11121112

11131113
#define SEPARATE_METHOD() do { \
11141114
if ((flags & ZEND_INHERITANCE_LAZY_CHILD_CLONE) \
1115-
&& child_scope != ce && child->type == ZEND_USER_FUNCTION) { \
1115+
&& child_scope != ce \
1116+
/* Trait scopes are fixed after inheritance. However, they are always duplicated. */ \
1117+
&& !(child_scope->ce_flags & ZEND_ACC_TRAIT) \
1118+
&& child->type == ZEND_USER_FUNCTION) { \
11161119
/* op_array wasn't duplicated yet */ \
11171120
zend_function *new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); \
11181121
memcpy(new_function, child, sizeof(zend_op_array)); \

0 commit comments

Comments
 (0)