Skip to content

Commit 66a7111

Browse files
committed
Do not set the inherited flag only for non-abstract constructors in zend_add_trait_method()
1 parent e94c76a commit 66a7111

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-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 __construct)
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public function __construct() {}
8+
}
9+
10+
trait T {
11+
#[\Override]
12+
public function __construct() {
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::__construct() 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 abstract __construct)
3+
--FILE--
4+
<?php
5+
6+
abstract class A {
7+
abstract public function __construct();
8+
}
9+
10+
trait T {
11+
#[\Override]
12+
public function __construct() {
13+
echo 'foo';
14+
}
15+
}
16+
17+
class D extends A {
18+
use T;
19+
}
20+
echo "Done";
21+
22+
?>
23+
--EXPECT--
24+
Done

Zend/zend_inheritance.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,8 @@ 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 = !(existing_fn->common.fn_flags & ZEND_ACC_PRIVATE);
1990+
inherited = !(existing_fn->common.fn_flags & ZEND_ACC_PRIVATE)
1991+
&& !(existing_fn->common.fn_flags & ZEND_ACC_CTOR && !(existing_fn->common.fn_flags & ZEND_ACC_ABSTRACT));
19911992
}
19921993
}
19931994

0 commit comments

Comments
 (0)