diff --git a/Zend/tests/gh14009.phpt b/Zend/tests/gh14009.phpt new file mode 100644 index 0000000000000..81325e814c271 --- /dev/null +++ b/Zend/tests/gh14009.phpt @@ -0,0 +1,41 @@ +--TEST-- +GH-14009: Traits inherit prototype +--FILE-- +common(); + } +} + +class B extends P { + protected function common() { + echo __METHOD__, "\n"; + } +} + +trait T { + protected function common() { + echo __METHOD__, "\n"; + } +} + +class C extends P { + use T; +} + +$a = new A(); +$a->test(new B()); +$a->test(new C()); + +?> +--EXPECT-- +B::common +T::common diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index cec0ffdb1853b..2bdd7039750f3 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1146,13 +1146,13 @@ static zend_always_inline inheritance_status do_inheritance_check_on_method_ex( parent = proto; } - if (!check_only && child->common.prototype != proto && child_zv) { + if (!check_only && child->common.prototype != proto) { do { if (child->common.scope != ce && child->type == ZEND_USER_FUNCTION) { if (ce->ce_flags & ZEND_ACC_INTERFACE) { /* Few parent interfaces contain the same method */ break; - } else { + } else if (child_zv) { /* op_array wasn't duplicated yet */ zend_function *new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); memcpy(new_function, child, sizeof(zend_op_array));