From 8ba00176f11fe255221c8fbedd264870bdbfedde Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Fri, 13 May 2011 20:28:34 +0000 Subject: [PATCH] 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 :-/ --- Zend/tests/traits/bugs/alias01.phpt | 26 ++++++++++++++++++++++++++ Zend/tests/traits/language010.phpt | 2 +- Zend/zend_compile.c | 19 ++++++++++++------- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 Zend/tests/traits/bugs/alias01.phpt diff --git a/Zend/tests/traits/bugs/alias01.phpt b/Zend/tests/traits/bugs/alias01.phpt new file mode 100644 index 0000000000..b60261efac --- /dev/null +++ b/Zend/tests/traits/bugs/alias01.phpt @@ -0,0 +1,26 @@ +--TEST-- +Aliases are applied to the correct methods, and only to them. +--FILE-- +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 diff --git a/Zend/tests/traits/language010.phpt b/Zend/tests/traits/language010.phpt index f7fea6f295..e550abb7bc 100644 --- a/Zend/tests/traits/language010.phpt +++ b/Zend/tests/traits/language010.phpt @@ -27,4 +27,4 @@ $o->world(); ?> --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 diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a16380f7b8..7c992b9cf7 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3662,10 +3662,13 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args, /* 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 @@ static int zend_traits_copy_functions(zend_function *fn TSRMLS_DC, int num_args, 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)) { -- 2.50.1