我在PHP中,我必须访问一个名称必须更改的对象的静态方法。
private $controlleur = null;
private static $instance = null;
private function __construct() {
$nomControlleur = "Controlleurs\_" . Session::singleton()->controlleur;
$this->controlleur = $nomControlleur::singleton();
}上面的代码给出了“语法错误意外::”。
我也尝试过编写{$nomControlleur}::singleton();但它给了我更多的错误,非常感谢您的帮助。
钢球
发布于 2009-09-19 20:03:14
使用:
$this->controlleur = call_user_func(array($nomControlleur, 'singleton'));或(仅限5.2.3+)
$this->controlleur = call_user_func($nomControlleur . '::singleton');发布于 2009-09-19 20:01:16
关于
$staticCall = $nonController."::singleton()";
$staticCall();发布于 2013-12-20 07:35:11
我认为在PHP5.3中,和__call()一样,PHP5.3也有__callStatic()。
因此您可以定义__callStatic(),未定义的静态方法调用将命中此方法。
有关更多详细信息和用法,请查看此处。
http://www.php.net/manual/en/language.oop5.overloading.php#object.callstatic
https://stackoverflow.com/questions/1449379
复制相似问题