summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2013-02-18 16:07:51 +0400
committerDmitry Stogov <dmitry@zend.com>2013-02-18 16:07:51 +0400
commit42437dd870de28eee6c9127f4c7e7c78ba8e0152 (patch)
treedd50c86f49124dfa80bc732ae997c0695966017c
parent7b0107cc5d3d90655957680ef9cf916dce6875a7 (diff)
downloadphp-git-42437dd870de28eee6c9127f4c7e7c78ba8e0152.tar.gz
Fixed bug #64070 (Inheritance with Traits failed with error)
-rw-r--r--NEWS1
-rw-r--r--Zend/tests/traits/bug64070.phpt36
-rw-r--r--Zend/zend_compile.c10
3 files changed, 41 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index bedc6a4dcf..e34b0c5d58 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ PHP NEWS
- Core:
. Implemented FR #64175 (Added HTTP codes as of RFC 6585). (Jonh Wendell)
. Fixed bug #64142 (dval to lval different behavior on ppc64). (Remi)
+ . Fixed bug #64070 (Inheritance with Traits failed with error). (Dmitry)
- CLI server:
. Fixed bug #64128 (buit-in web server is broken on ppc64). (Remi)
diff --git a/Zend/tests/traits/bug64070.phpt b/Zend/tests/traits/bug64070.phpt
new file mode 100644
index 0000000000..a5ee3b6a5f
--- /dev/null
+++ b/Zend/tests/traits/bug64070.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Bug #64070 (Inheritance with Traits failed with error)
+--FILE--
+<?php
+trait first_trait
+{
+ function first_function()
+ {
+ echo "From First Trait\n";
+ }
+}
+
+trait second_trait
+{
+ use first_trait {
+ first_trait::first_function as second_function;
+ }
+
+ function first_function()
+ {
+ echo "From Second Trait\n";
+ }
+}
+
+class first_class
+{
+ use second_trait;
+}
+
+$obj = new first_class();
+$obj->first_function();
+$obj->second_function();
+?>
+--EXPECT--
+From Second Trait
+From First Trait
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 8f4f9c47b8..a3f4fe5dd6 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3786,7 +3786,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
overriden = va_arg(args, HashTable**);
exclude_table = va_arg(args, HashTable*);
- fnname_len = strlen(fn->common.function_name);
+ fnname_len = hash_key->nKeyLength - 1;
/* apply aliases which are qualified with a class name, there should not be any ambiguity */
if (ce->trait_aliases) {
@@ -3797,7 +3797,7 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
if (alias->alias != NULL
&& (!alias->trait_method->ce || fn->common.scope == alias->trait_method->ce)
&& 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)) {
+ && (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, hash_key->arKey, fnname_len) == 0)) {
fn_copy = *fn;
/* 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,
}
}
- lcname = zend_str_tolower_dup(fn->common.function_name, fnname_len);
+ lcname = hash_key->arKey;
if (exclude_table == NULL || zend_hash_find(exclude_table, lcname, fnname_len, &dummy) == FAILURE) {
/* 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,
if (alias->alias == NULL && alias->modifiers != 0
&& (!alias->trait_method->ce || fn->common.scope == alias->trait_method->ce)
&& (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)) {
+ && (zend_binary_strcasecmp(alias->trait_method->method_name, alias->trait_method->mname_len, lcname, fnname_len) == 0)) {
fn_copy.common.fn_flags = alias->modifiers | (fn->common.fn_flags ^ (fn->common.fn_flags & ZEND_ACC_PPP_MASK));
@@ -3851,8 +3851,6 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args,
zend_add_trait_method(ce, fn->common.function_name, lcname, fnname_len+1, &fn_copy, overriden TSRMLS_CC);
}
- efree(lcname);
-
return ZEND_HASH_APPLY_KEEP;
}
/* }}} */