Skip to content

Commit c5982c9

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix incorrect inheritance of private trait methods (#14163)
2 parents 60336de + da5b43f commit c5982c9

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
@@ -2024,7 +2024,8 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
20242024
do_inheritance_check_on_method(
20252025
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
20262026
ce, NULL,
2027-
ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY | ZEND_INHERITANCE_SET_CHILD_PROTO |
2027+
ZEND_INHERITANCE_CHECK_PROTO | ZEND_INHERITANCE_CHECK_VISIBILITY |
2028+
ZEND_INHERITANCE_SET_CHILD_CHANGED| ZEND_INHERITANCE_SET_CHILD_PROTO |
20282029
ZEND_INHERITANCE_RESET_CHILD_OVERRIDE);
20292030
}
20302031
}

0 commit comments

Comments
 (0)