Skip to content

Commit e94c76a

Browse files
committed
Set the inherited flag only for non-private methods in zend_add_trait_method()
1 parent a45bab0 commit e94c76a

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
#[Override] attribute in trait does not check for parent class implementations (Variant with private parent method)
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
private function foo(): void {}
8+
}
9+
10+
trait T {
11+
#[\Override]
12+
public function foo(): void {
13+
echo 'foo';
14+
}
15+
}
16+
17+
class D extends A {
18+
use T;
19+
}
20+
echo "Done";
21+
22+
?>
23+
--EXPECTF--
24+
Fatal error: D::foo() has #[\Override] attribute, but no matching parent method exists in %s on line %d
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
#[Override] attribute in trait does not check for parent class implementations (Variant with protected parent method)
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
protected function foo(): void {}
8+
}
9+
10+
trait T {
11+
#[\Override]
12+
public function foo(): void {
13+
echo 'foo';
14+
}
15+
}
16+
17+
class D extends A {
18+
use T;
19+
}
20+
echo "Done";
21+
22+
?>
23+
--EXPECTF--
24+
Done

Zend/zend_inheritance.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
19871987
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
19881988
ce, NULL, /* check_visibility */ 1);
19891989

1990-
inherited = true;
1990+
inherited = !(existing_fn->common.fn_flags & ZEND_ACC_PRIVATE);
19911991
}
19921992
}
19931993

0 commit comments

Comments
 (0)