PHP 5.6, Apache 2.4 | Windows 7, OpenServer
(static function () {
return true;
})();
Why this throws syntax error?
syntax error, unexpected '('
But http://php.net/manual/en/functions.anonymous.php
PS: Also ->call doesn't work too... (unexpected '->')
Here's the problem. It's not the static part that's not working:
$f = static function () { return true; }; $f(); //Works in PHP 5.4+
It's the declaring and calling that doesn't work:
(static function () { return true; })(); //Works in PHP 7+
Problem is the documentation is saying that the first syntax is valid in PHP 5.4+ but uses examples that require PHP 7+ to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With