php 5.6,apache 2.4 |Windows 7,OpenServer
(static function () {
return true;
})();
为什么会引发语法错误?
syntax error, unexpected '('
但是http://php.net/manual/en/functions.anonymous.php
ps:另外 ->通话也不起作用...(意外' ->')
这是问题。这不是不起作用的静态部分:
$f = static function () { return true; }; $f(); //Works in PHP 5.4+
是声明和呼叫无效:
(static function () { return true; })(); //Works in PHP 7+
问题是文档说的是第一个语法在PHP 5.4 中有效,但使用需要PHP 7 工作的示例。
这在PHP 5.x
中不起作用您需要php 7 来运行它。
阅读有关它的更多信息:https://stackoverflow.com/a/3605701/372172