是的。该语法是在 5.3 中引入的
要解决 call_user_func:
call_user_func(array($className, $funcName), $arg1, $arg2, $arg3);
or call_user_func_array
:
call_user_func_array(array($className, $funcName), array($arg1, $arg2, $arg3));
但另一方面,你想做的事情并没有真正意义......
为什么将其作为静态函数?你的构造函数在implementation
无论如何都在期待一个对象(这就是strategyInterface $strategy
在寻找)。传递字符串不起作用,因为字符串不实现接口。所以我要做的就是使接口成为非静态的,然后执行以下操作:
$strategy = new StrategyB();
$implementation = new Implementation($strategy);
然后,在构造函数中:
$strFormat = $strategy->getFormatString();
或者,如果您确实仍然希望该方法是静态的,您可以这样做:
$strFormat = call_user_func(array(get_class($strategy), 'getFormatString'));
Oh, and = & new
联轴是已弃用(而且无论如何也不会做你认为它会做的事情)。