How can I call a static method from a class if all I have is a string of the class name?

后端 未结 6 1293
自闭症患者
自闭症患者 2020-12-09 01:05

How would I get something like this to work?

$class_name = \'ClassPeer\';
$class_name::doSomething();
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 01:42

    Reflection (PHP 5 supports it) is how you'd do this. Read that page and you should be able to figure out how to invoke the function like that.

    $func = new ReflectionFunction('somefunction');
    $func->invoke();
    

    Documentation Link

提交回复
热议问题