|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66010 "getClosure" should return methods of a given Trait
Submitted: 2013-10-31 12:58 UTC Modified: 2015-01-25 04:22 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: caiounif at gmail dot com Assigned:
Status: No Feedback Package: Reflection related
PHP Version: 5.4.21 OS: Ubuntu 13.10
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-10-31 12:58 UTC] caiounif at gmail dot com
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-12 22:11 UTC]
-Status: Open +Status: Feedback
 [2015-01-12 22:11 UTC]
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.
 [2015-01-25 04:22 UTC] php-bugs at lists dot php dot net
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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 29 05:03:39 2023 UTC