Bug #63399 [Ana->Csd]: ReflectionClass::getTraitAliases() incorrectly resolves traitnames
| From: | laruence@php.net | Date: | Wed, 31 Oct 2012 03:13:53 +0000 |
| Subject: | Bug #63399 [Ana->Csd]: ReflectionClass::getTraitAliases() incorrectly resolves traitnames | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-174433@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63399&edit=1
ID: 63399
Updated by: laruence@php.net
Reported by: r dot wilczek at web-appz dot de
Summary: ReflectionClass::getTraitAliases() incorrectly
resolves traitnames
-Status: Analyzed
+Status: Closed
Type: Bug
Package: Reflection related
Operating System: Linux x86_64
PHP Version: 5.4.7RC1
Assigned To: laruence
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7886f46b560c51f235da35a33c8cd0e6479c9360
Log: Fixed bug #63399 (ReflectionClass::getTraitAliases() incorrectly resolves traitnames)
Previous Comments:
------------------------------------------------------------------------
[2012-10-30 16:52:32] r dot wilczek at web-appz dot de
I think, that https://github.com/php/php-src/blob/master/ext/reflection/tests/traits005.phpt
just shows the actual implementation and does not define expected behaviour.
... who would seriously expect '(null)'?
------------------------------------------------------------------------
[2012-10-30 15:08:40] laruence@php.net
A quick fix is:
iff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index deabcbe..7c51cf6 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -4473,7 +4473,7 @@ ZEND_METHOD(reflection_class, getTraitAliases)
zend_trait_method_reference *cur_ref = ce-
>trait_aliases[i]->trait_method;
if (ce->trait_aliases[i]->alias) {
- method_name_len = spprintf(&method_name, 0,
"%s::%s", cur_ref->class_name, cur_ref->method_name);
+ method_name_len = spprintf(&method_name, 0,
"%s::%s", cur_ref->ce->name, cur_ref->method_name);
add_assoc_stringl_ex(return_value, ce-
>trait_aliases[i]->alias, ce->trait_aliases[i]->alias_len + 1, method_n
ame, method_name_len, 0);
}
i++;
but seems an existsing test take it as a expect output, see:
https://github.com/php/php-src/blob/master/ext/reflection/tests/traits005.phpt
will verify it later.
------------------------------------------------------------------------
[2012-10-30 14:19:43] r dot wilczek at web-appz dot de
Description:
------------
When aliasing an importing traitmethod without explicitely declaring the trait's name,
ReflectionClass::getTraitAliases() renders the traitname as '(null)'.
The method should render the correct traitname, as if the aliasing had been done using the full
qualifier.
(Actually, my PHP-version is 5.4.7, not 5.4.7RC1)
Test script:
---------------
trait MyTrait
{
public function run() {}
}
class MyClass
{
use MyTrait {
run as execute;
}
}
var_export((new \ReflectionClass('MyClass'))->getTraitAliases());
Expected result:
----------------
array (
'execute' => 'MyTrait::run',
)
Actual result:
--------------
array (
'execute' => '(null)::run',
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63399&edit=1