The php static method calls a class that is in a variable

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

+4
source share
1 answer

You can use call_user_funcfor this.

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

Or:

call_user_func(array($name, 'methodName'));
+3
source

Source: https://habr.com/ru/post/1612828/


All Articles