简体   繁体   English

PHP调用静态类的方法

[英]Php call static method of class which is in variable

I have a namespace App\\Term which is saved as a property: $this->name = 'App\\Term' . 我有一个命名空间App\\Term ,它保存为属性: $this->name = 'App\\Term' How can I call a static method of this class like $this->name::methodName() ? 如何调用此类的静态方法,例如$this->name::methodName() Or is there another solution for this problem? 还是对此问题有另一种解决方案?

You can use call_user_func for this. 您可以为此使用call_user_func

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

Or: 要么:

call_user_func(array($name, 'methodName'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM