5

I have a namespace App\Term which is saved as a property: $this->name = 'App\Term'. How can I call a static method of this class like $this->name::methodName() ? Or is there another solution for this problem?

2
  • Does $name::methodName() not work? Commented Oct 22, 2015 at 20:01
  • I updated the question. It should be not a simple variable like $name. It is a property: $this->name Commented Oct 22, 2015 at 20:28

1 Answer 1

5

You can use call_user_func for this.

call_user_func($name.'::methodName');

Or:

call_user_func(array($name, 'methodName'));
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. I works even with property: call_user_func($this->name.'::methodName');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.