Req #66010 [Opn->Fbk]: "getClosure" should return methods of a given Trait
| From: | danack@php.net | Date: | Mon, 12 Jan 2015 22:11:39 +0000 |
| Subject: | Req #66010 [Opn->Fbk]: "getClosure" should return methods of a given Trait | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189916@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66010&edit=1
ID: 66010
Updated by: danack@php.net
Reported by: caiounif at gmail dot com
Summary: "getClosure" should return methods of a given Trait
-Status: Open
+Status: Feedback
Type: Feature/Change Request
Package: Reflection related
Operating System: Ubuntu 13.10
PHP Version: 5.4.21
Block user comment: N
Private report: N
New Comment:
Hi, it's unclear what you're trying to do. You say that you're trying to get the
methods of a trait through reflection - but your code is actually trying to create a closure, that
could be called.
That is not possible.....traits are only callable once they've been included in a class. It
would be a bit like trying to get a closure of an interface....until it's included inside a
class it just isn't a real thing that can be called.
Calling getMethods on the reflection for the trait does return all the information about a traits
methods. If you mean something else by "get its methods" please can you clarify.
Previous Comments:
------------------------------------------------------------------------
[2013-10-31 12:58:45] caiounif at gmail dot com
Description:
------------
Since Traits can't be instantiated, it is impossible to get its methods.
Test script:
---------------
trait foo {
protected $bar;
public function set_bar ($bar) {
$this->bar = $bar;
}
}
$reflection = new ReflectionClass ("foo");
print_r ($reflection->getMethods ()[0]->getClosure ());
Expected result:
----------------
Closure Object
(
[this] => EMPTY (WILD GUESS)
[parameter] => Array
(
[$bar] => <required>
)
)
Actual result:
--------------
PHP Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 0 given
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66010&edit=1