Skip to content

Commit 8872357

Browse files
pmmagalaruence
authored andcommitted
Fix #76700 - Methods with altered visibility need to be added again
1 parent 2b1d79c commit 8872357

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Zend/tests/traits/bug76700.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #76700 (false-positive "Error: Call to protected method" when using trait aliases)
3+
--FILE--
4+
<?php
5+
trait T1
6+
{
7+
protected function aa() { echo 123; }
8+
}
9+
10+
trait T2
11+
{
12+
use T1 {
13+
aa as public;
14+
}
15+
}
16+
17+
class A
18+
{
19+
use T1;
20+
}
21+
22+
class B extends A
23+
{
24+
use T2;
25+
}
26+
27+
$b = new B();
28+
$b->aa();
29+
30+
--EXPECT--
31+
123

Zend/zend_inheritance.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,8 +1178,10 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s
11781178
zend_function *new_fn;
11791179

11801180
if ((existing_fn = zend_hash_find_ptr(&ce->function_table, key)) != NULL) {
1181-
/* if it is the same function regardless of where it is coming from, there is no conflict and we do not need to add it again */
1182-
if (existing_fn->op_array.opcodes == fn->op_array.opcodes) {
1181+
/* if it is the same function with the same visibility regardless of where it is coming from */
1182+
/* there is no conflict and we do not need to add it again */
1183+
if (existing_fn->op_array.opcodes == fn->op_array.opcodes &&
1184+
(existing_fn->common.fn_flags & ZEND_ACC_PPP_MASK) == (fn->common.fn_flags & ZEND_ACC_PPP_MASK)) {
11831185
return;
11841186
}
11851187

0 commit comments

Comments
 (0)