diff options
author | Stefan Marr <gron@php.net> | 2011-05-13 20:28:34 +0000 |
---|---|---|
committer | Stefan Marr <gron@php.net> | 2011-05-13 20:28:34 +0000 |
commit | 8ba00176f11fe255221c8fbedd264870bdbfedde (patch) | |
tree | 6d6312420ae82de4f641ff0e9d2ecdb9e7bbabad | |
parent | db0c957f028f116a1518f3cc81edc77053053eed (diff) | |
download | php-git-8ba00176f11fe255221c8fbedd264870bdbfedde.tar.gz |
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 :-/
-rw-r--r-- | Zend/tests/traits/bugs/alias01.phpt | 26 | ||||
-rw-r--r-- | Zend/tests/traits/language010.phpt | 2 | ||||
-rw-r--r-- | Zend/zend_compile.c | 19 |
3 files changed, 39 insertions, 8 deletions
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-- +<?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 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)) { |