How can I call a static method on a variable class?

前端 未结 6 1892
轻奢々
轻奢々 2020-12-15 15:44

I\'m trying to make some kind of function that loads and instantiates a class from a given variable. Something like this:



        
6条回答
  •  渐次进展
    2020-12-15 16:17

    You can use call_user_func():

    $class = call_user_func(array($class, 'getInstance'));
    

    The first argument is a callback type containing the classname and method name in this case.

提交回复
热议问题