Skip to content

Commit 42437dd

Browse files
committed
Fixed bug #64070 (Inheritance with Traits failed with error)
1 parent 7b0107c commit 42437dd

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Implemented FR #64175 (Added HTTP codes as of RFC 6585). (Jonh Wendell)
77
. Fixed bug #64142 (dval to lval different behavior on ppc64). (Remi)
8+
. Fixed bug #64070 (Inheritance with Traits failed with error). (Dmitry)
89

910
- CLI server:
1011
. Fixed bug #64128 (buit-in web server is broken on ppc64). (Remi)

Zend/tests/traits/bug64070.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Bug #64070 (Inheritance with Traits failed with error)
3+
--FILE--
4+
<?php
5+
trait first_trait
6+
{
7+
function first_function()
8+
{
9+
echo "From First Trait\n";
10+
}
11+
}
12+
13+
trait second_trait
14+
{
15+
use first_trait {
16+
first_trait::first_function as second_function;
17+
}
18+
19+
function first_function()
20+
{
21+
echo "From Second Trait\n";
22+
}
23+
}
24+
25+
class first_class
26+
{
27+
use second_trait;
28+
}
29+
30+
$obj = new first_class();
31+
$obj->first_function();
32+
$obj->second_function();
33+
?>
34+
--EXPECT--
35+
From Second Trait
36+
From First Trait

Zend/zend_compile.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,7 +3786,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
37863786
overriden = va_arg(args, HashTable**);
37873787
exclude_table = va_arg(args, HashTable*);
37883788

3789-
fnname_len = strlen(fn->common.function_name);
3789+
fnname_len = hash_key->nKeyLength - 1;
37903790

37913791
/* apply aliases which are qualified with a class name, there should not be any ambiguity */
37923792
if (ce->trait_aliases) {
@@ -3797,7 +3797,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
37973797
if (alias->alias != NULL
37983798
&& (!alias->trait_method->ce || fn->common.scope == alias->trait_method->ce)
37993799
&& alias->trait_method->mname_len == fnname_len
3800-
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, fn->common.function_name, fnname_len) == 0)) {
3800+
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, hash_key->arKey, fnname_len) == 0)) {
38013801
fn_copy = *fn;
38023802

38033803
/* if it is 0, no modifieres has been changed */
@@ -3819,7 +3819,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
38193819
}
38203820
}
38213821

3822-
lcname = zend_str_tolower_dup(fn->common.function_name, fnname_len);
3822+
lcname = hash_key->arKey;
38233823

38243824
if (exclude_table == NULL || zend_hash_find(exclude_table, lcname, fnname_len, &dummy) == FAILURE) {
38253825
/* is not in hashtable, thus, function is not to be excluded */
@@ -3834,7 +3834,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
38343834
if (alias->alias == NULL && alias->modifiers != 0
38353835
&& (!alias->trait_method->ce || fn->common.scope == alias->trait_method->ce)
38363836
&& (alias->trait_method->mname_len == fnname_len)
3837-
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, fn->common.function_name, fnname_len) == 0)) {
3837+
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, lcname, fnname_len) == 0)) {
38383838

38393839
fn_copy.common.fn_flags = alias->modifiers | (fn->common.fn_flags ^ (fn->common.fn_flags & ZEND_ACC_PPP_MASK));
38403840

@@ -3851,8 +3851,6 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
38513851
zend_add_trait_method(ce, fn->common.function_name, lcname, fnname_len+1, &fn_copy, overriden TSRMLS_CC);
38523852
}
38533853

3854-
efree(lcname);
3855-
38563854
return ZEND_HASH_APPLY_KEEP;
38573855
}
38583856
/* }}} */

0 commit comments

Comments
 (0)