PHP 静态匿名调用不起​​作用

PHP static anonymous call doesn't work

PHP 5.6,阿帕奇 2.4 | Windows7、OpenServer

(static function () {
    return true;
})();

为什么会抛出语法错误?

syntax error, unexpected '('

但是http://php.net/manual/en/functions.anonymous.php
PS:另外 ->call 也不起作用...(意外的“->”)

这在 PHP 5.x

中不起作用

你需要 PHP 7+ 到 运行 它。

了解更多信息:

问题来了。不是静态部分不起作用:

$f = static function () { return true; }; $f(); //Works in PHP 5.4+

是声明调用不行:

(static function () { return true; })(); //Works in PHP 7+

问题是文档说第一个语法在 PHP 5.4+ 中有效,但使用的示例需要 PHP 7+ 才能工作。