Skip to content

Commit d77eb41

Browse files
committed
Merge branch 'PHP-5.4' into PHP-5.5
* PHP-5.4: Fixed bug #64070 (Inheritance with Traits failed with error) Conflicts: NEWS Zend/zend_compile.c
2 parents 91538e4 + 42437dd commit d77eb41

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

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
@@ -3975,7 +3975,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
39753975
overriden = va_arg(args, HashTable**);
39763976
exclude_table = va_arg(args, HashTable*);
39773977

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

39803980
/* apply aliases which are qualified with a class name, there should not be any ambiguity */
39813981
if (ce->trait_aliases) {
@@ -3986,7 +3986,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
39863986
if (alias->alias != NULL
39873987
&& (!alias->trait_method->ce || fn->common.scope == alias->trait_method->ce)
39883988
&& alias->trait_method->mname_len == fnname_len
3989-
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, fn->common.function_name, fnname_len) == 0)) {
3989+
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, hash_key->arKey, fnname_len) == 0)) {
39903990
fn_copy = *fn;
39913991

39923992
/* if it is 0, no modifieres has been changed */
@@ -4008,7 +4008,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
40084008
}
40094009
}
40104010

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

40134013
if (exclude_table == NULL || zend_hash_find(exclude_table, lcname, fnname_len, &dummy) == FAILURE) {
40144014
/* is not in hashtable, thus, function is not to be excluded */
@@ -4023,7 +4023,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
40234023
if (alias->alias == NULL && alias->modifiers != 0
40244024
&& (!alias->trait_method->ce || fn->common.scope == alias->trait_method->ce)
40254025
&& (alias->trait_method->mname_len == fnname_len)
4026-
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, fn->common.function_name, fnname_len) == 0)) {
4026+
&& (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, lcname, fnname_len) == 0)) {
40274027

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

@@ -4040,8 +4040,6 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
40404040
zend_add_trait_method(ce, fn->common.function_name, lcname, fnname_len+1, &fn_copy, overriden TSRMLS_CC);
40414041
}
40424042

4043-
efree(lcname);
4044-
40454043
return ZEND_HASH_APPLY_KEEP;
40464044
}
40474045
/* }}} */

0 commit comments

Comments
 (0)