Skip to content

Bug 64070 fix, traits aliasing of collided methods #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Zend/tests/bug64070.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
Bug #64070 (Inheritance with traits and aliased methods)
--FILE--
<?php

trait Foo {
public function bar() {
echo "foo\n";
}
}

trait Bar {
use Foo {
Foo::bar as foo;
}

public function bar() {
echo "bar\n";
}
}

class Boo {
use Bar;
}

$n = new Boo;
$n->bar();
$n->foo();

?>
--EXPECT--
bar
foo
3 changes: 3 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3988,6 +3988,9 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
&& alias->trait_method->mname_len == fnname_len
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, fn->common.function_name, fnname_len) == 0)) {
fn_copy = *fn;

/* Switch the name of the aliased function to the alias so that derived classes will get alias and not original name */
fn_copy.common.function_name = estrndup(alias->alias, alias->alias_len);

/* if it is 0, no modifieres has been changed */
if (alias->modifiers) {
Expand Down