Bug #64963 [Fbk->NoF]: ReflectionClass::getMethods does not identify traits
| From: | php-bugs at lists dot php dot net | Date: | Tue, 15 Oct 2013 11:54:44 +0000 |
| Subject: | Bug #64963 [Fbk->NoF]: ReflectionClass::getMethods does not identify traits | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182245@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64963&edit=1
ID: 64963
Updated by: php-bugs@lists.php.net
Reported by: alasdair at softhome dot net
Summary: ReflectionClass::getMethods does not identify traits
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Reflection related
Operating System: Debian Wheezy
PHP Version: 5.4.15
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2013-06-27 09:58:04] alasdair at softhome dot net
Nice blog David. Good to see other people battling with this frustration as well. Will be looking
more indepth at your work around to see if it helps what I was planning on doing.
------------------------------------------------------------------------
[2013-06-27 08:46:27] david at mouf-php dot com
I have a very strong feeling about this.
I understand that the PHP implementation of traits is about copying traits into classes. Yet, the
whole purpose of a Reflection API is to find where properties / methods are declared.
I have a simple question: I need to be able to find in which class/trait a method is declared. I
need this for my PHP framework (Mouf), that is heavily relying in reflection to build a graphical
dependency injection system.
I've written a lengthy blog post explaining what the problems with the current Reflection API
are, and hopefully, how to find a (not perfect) work around.
You can find the blog post here: http://mouf-php.com/blog/php_reflection_api_traits
I really hope we can agree this is indeed something that needs to be fixed, as the workaround
I've put in place are far from perfect.
For technical details, my PHP version: PHP 5.4.9-4ubuntu2.1.
------------------------------------------------------------------------
[2013-06-03 17:26:15] alasdair at softhome dot net
In that case should there not be some kind of isTrait for the ReflectionMethod
the same way there is for the ReflectionClass?
------------------------------------------------------------------------
[2013-06-03 16:27:04] laruence@php.net
the methods of traits are copied into class.
so, in theory, there is nothing wrong.
------------------------------------------------------------------------
[2013-06-03 13:57:33] alasdair at softhome dot net
Description:
------------
Specific PHP version PHP 5.4.15-1~dotdeb.2
Executing ReflectionClass::getMethods on a class using traits does not
differentiate between methods within the class or methods within the trait being
used, whereas calling ReflectionMethod::getDeclaringClass on the class with the
method identifies it as coming from the trait.
Test script:
---------------
<?php
trait t {
function f() {
//do stuff
}
}
Class c {
use t;
function f2() {
//do stuff
}
}
$class = new ReflectionClass('c');
print_r($class->getMethods());
?>
Expected result:
----------------
Array
(
[0] => ReflectionMethod Object
(
[name] => f2
[class] => c
)
[1] => ReflectionMethod Object
(
[name] => f
[class] => t
)
)
or
Array
(
[0] => ReflectionMethod Object
(
[name] => f2
[class] => c
)
[1] => ReflectionMethod Object
(
[name] => f
[trait] => t
)
)
Actual result:
--------------
Array
(
[0] => ReflectionMethod Object
(
[name] => f2
[class] => c
)
[1] => ReflectionMethod Object
(
[name] => f
[class] => c
)
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64963&edit=1