gron                                     Fri, 13 May 2011 20:28:34 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=310999

Log:
Fixed a inconsitent condition for aliasing traits.

- missed a failing Traits test, but is now fixed, and the bug covered by a 
dedicated test
# Should always comment conditions that go over more than two lines :-/

Changed paths:
    A   php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt
    U   php/php-src/trunk/Zend/tests/traits/language010.phpt
    U   php/php-src/trunk/Zend/zend_compile.c

Added: php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt                       
        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/alias01.phpt       2011-05-13 
20:28:34 UTC (rev 310999)
@@ -0,0 +1,26 @@
+--TEST--
+Aliases are applied to the correct methods, and only to them.
+--FILE--
+<?php
+trait T1 {
+  function m1() { echo "T:m1\n"; }
+  function m2() { echo "T:m2\n"; }
+}
+
+class C1 {
+  use T1 { m1 as a1; }
+}
+
+$o = new C1;
+$o->m1();
+$o->a1();
+$o->m2();
+$o->a2();
+
+?>
+--EXPECTF--
+T:m1
+T:m1
+T:m2
+
+Fatal error: Call to undefined method C1::a2() in %s on line %d

Modified: php/php-src/trunk/Zend/tests/traits/language010.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language010.phpt        2011-05-13 
19:56:04 UTC (rev 310998)
+++ php/php-src/trunk/Zend/tests/traits/language010.phpt        2011-05-13 
20:28:34 UTC (rev 310999)
@@ -27,4 +27,4 @@

 ?>
 --EXPECTF--
-Fatal error: Failed to add trait method (world) to the trait table. There is 
probably already a trait method with the same name in %s on line %d
\ No newline at end of file
+Fatal error: Trait method world has not been applied, because there are 
collisions with other trait methods on MyClass in %s on line %d
\ No newline at end of file

Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c       2011-05-13 19:56:04 UTC (rev 
310998)
+++ php/php-src/trunk/Zend/zend_compile.c       2011-05-13 20:28:34 UTC (rev 
310999)
@@ -3662,10 +3662,13 @@
        /* apply aliases which are qualified with a class name, there should 
not be any ambiguity */
        if (aliases) {
                while (aliases[i]) {
-                       if (!aliases[i]->trait_method->ce || (fn->common.scope 
== aliases[i]->trait_method->ce &&
-                               
(zend_binary_strcasecmp(aliases[i]->trait_method->method_name,
+
+                       if (/* Scope unset or equal to the function we compare 
to */
+          (!aliases[i]->trait_method->ce || fn->common.scope == 
aliases[i]->trait_method->ce)
+          && /* and, the alias applies to fn */
+          (zend_binary_strcasecmp(aliases[i]->trait_method->method_name,
                                                                                
                                                 
aliases[i]->trait_method->mname_len,
-                                                                               
                                                 fn->common.function_name, 
fnname_len) == 0))) {
+                                                                               
                                                 fn->common.function_name, 
fnname_len) == 0)) {
                                if (aliases[i]->alias) {
                                        fn_copy = *fn;
                                        
zend_traits_duplicate_function(&fn_copy, estrndup(aliases[i]->alias, 
aliases[i]->alias_len) TSRMLS_CC);
@@ -3703,10 +3706,12 @@
                if (aliases) {
                        i = 0;
                        while (aliases[i]) {
-                               if ((!aliases[i]->trait_method->ce || 
fn->common.scope == aliases[i]->trait_method->ce) &&
-                                       
(zend_binary_strcasecmp(aliases[i]->trait_method->method_name,
-                                                                               
                                                         
aliases[i]->trait_method->mname_len,
-                                                                               
                                                         
fn->common.function_name, fnname_len) == 0)) {
+                               if (/* Scope unset or equal to the function we 
compare to */
+            (!aliases[i]->trait_method->ce || fn->common.scope == 
aliases[i]->trait_method->ce)
+            && /* and, the alias applies to fn */
+                                         
(zend_binary_strcasecmp(aliases[i]->trait_method->method_name,
+                                    aliases[i]->trait_method->mname_len,
+                                                                               
                                                          
fn->common.function_name, fnname_len) == 0)) {
                                        if (!aliases[i]->alias && 
aliases[i]->modifiers) { /* if it is 0, no modifieres has been changed */
                                                fn_copy.common.fn_flags = 
aliases[i]->modifiers;
                                                if (!(aliases[i]->modifiers & 
ZEND_ACC_PPP_MASK)) {

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

Reply via email to