Skip to content

Commit

Permalink
Fix prototype for trait methods
Browse files Browse the repository at this point in the history
  • Loading branch information
iluuu1994 committed Apr 20, 2024
1 parent b3e26c3 commit 6be25dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions Zend/tests/gh14009.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
GH-14009: Traits inherit prototype
--FILE--
<?php

class P {
protected function common() {
throw new Exception('Unreachable');
}
}

class A extends P {
public function test(P $sibling) {
$sibling->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
4 changes: 2 additions & 2 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 6be25dc

Please sign in to comment.