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

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

How would I get something like this to work?

$class_name = \'ClassPeer\';
$class_name::doSomething();
6条回答
  •  -上瘾入骨i
    2020-12-09 01:58

    Use call_user_func. Also read up on PHP callbacks.

    call_user_func(array($class_name, 'doSomething'), $arguments);
    

提交回复
热议问题