php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63399 ReflectionClass::getTraitAliases() incorrectly resolves traitnames
Submitted: 2012-10-30 14:19 UTC Modified: 2012-10-30 15:09 UTC
From: r dot wilczek at web-appz dot de Assigned: laruence (profile)
Status: Closed Package: Reflection related
PHP Version: 5.4.7RC1 OS: Linux x86_64
Private report: No CVE-ID: None
 [2012-10-30 14:19 UTC] 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',
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-30 15:08 UTC] 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 15:08 UTC] laruence@php.net
-Status: Open +Status: Analyzed
 [2012-10-30 15:09 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2012-10-30 16:52 UTC] 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-31 03:13 UTC] laruence@php.net
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)
 [2012-10-31 03:13 UTC] laruence@php.net
-Status: Analyzed +Status: Closed
 [2012-10-31 03:14 UTC] laruence@php.net
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)
 [2014-10-07 23:21 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=7886f46b560c51f235da35a33c8cd0e6479c9360
Log: Fixed bug #63399 (ReflectionClass::getTraitAliases() incorrectly resolves traitnames)
 [2014-10-07 23:32 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=7886f46b560c51f235da35a33c8cd0e6479c9360
Log: Fixed bug #63399 (ReflectionClass::getTraitAliases() incorrectly resolves traitnames)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC