Skip to content

Commit 7a9e0fb

Browse files
authored
Fix incorrect inheritance of private trait methods (#14163)
The bug was introduced in c6b75f9
1 parent c6b75f9 commit 7a9e0fb

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Zend/tests/gh14009_005.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-14009: Traits inherit prototype
3+
--FILE--
4+
<?php
5+
6+
trait T {
7+
private function test($s) {
8+
echo $s . " -> ". __CLASS__ . "::" . __METHOD__ . "\n";
9+
}
10+
}
11+
12+
class A {
13+
use T;
14+
public function foo() {
15+
$this->test(__METHOD__);
16+
}
17+
public function bar() {
18+
$this->test(__METHOD__);
19+
}
20+
}
21+
22+
class B extends A {
23+
use T;
24+
public function foo() {
25+
$this->test(__METHOD__);
26+
}
27+
}
28+
29+
(new A)->foo();
30+
(new A)->bar();
31+
(new B)->foo();
32+
(new B)->bar();
33+
?>
34+
--EXPECT--
35+
A::foo -> A::T::test
36+
A::bar -> A::T::test
37+
B::foo -> B::T::test
38+
A::bar -> A::T::test

Zend/zend_inheritance.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,8 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
19361936
do_inheritance_check_on_method(
19371937
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
19381938
ce, NULL,
1939-
ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY | ZEND_INHERITANCE_SET_CHILD_PROTO);
1939+
ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY |
1940+
ZEND_INHERITANCE_SET_CHILD_CHANGED| ZEND_INHERITANCE_SET_CHILD_PROTO);
19401941
}
19411942
}
19421943
/* }}} */

0 commit comments

Comments
 (0)