Commit:    42437dd870de28eee6c9127f4c7e7c78ba8e0152
Author:    Dmitry Stogov <dmi...@zend.com>         Mon, 18 Feb 2013 16:07:51 
+0400
Parents:   7b0107cc5d3d90655957680ef9cf916dce6875a7
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=42437dd870de28eee6c9127f4c7e7c78ba8e0152

Log:
Fixed bug #64070 (Inheritance with Traits failed with error)

Bugs:
https://bugs.php.net/64070

Changed paths:
  M  NEWS
  A  Zend/tests/traits/bug64070.phpt
  M  Zend/zend_compile.c


Diff:
diff --git a/NEWS b/NEWS
index bedc6a4..e34b0c5 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 0000000..a5ee3b6
--- /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 8f4f9c4..a3f4fe5 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;
 }
 /* }}} */


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to