这个
question让我很好奇地使用语言结构与PHP的魔法方法相结合.我已经创建了一个演示代码:
@H_404_10@
更新PHP 7
<?PHP class Testing { public function scopeList() { echo "scopeList"; } public function __call($method,$parameters) { if($method == "list") { $this->scopeList(); } } public static function __callStatic($method,$parameters) { $instance = new static; call_user_func_array([$instance,$method],$parameters); } } //Testing::list(); $testing = new Testing(); $testing->list();
为什么Testing :: list()抛出一个语法错误,而$test-> list()没有?
由于php reserved keywords都应该失败?
PHP 7解决了所描述的行为,并实现了一个名为上下文敏感词典的功能,由marcio提出.
PHP 7之前的情况
在PHP甚至知道通过__callStatic()可用的方法的事实之前,会抛出语法错误,它发生在解析阶段.
您描述的行为似乎是PHP解析器中的一个错误,至少应该在文档中描述的不一致.
我会file a bug report.好抓住!
更新:OP已经提供了一个错误报告,可以在这里找到:https://bugs.php.net/bug.php?id=71157