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

后端 未结 6 1252
自闭症患者
自闭症患者 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:43

    if you need to adjust the namespace

    $call = call_user_func(array('\\App\\Models\\'.$class_name, "doSomething"));
    

提交回复
热议问题