Действительно ли статическая анонимная функция PHP работает?
Я пытаюсь выучить PHP, и теперь я застрял в «статической анонимной функции».
Я нашел это в учебнике (http://www.slideshare.net/melechi/php-53-part-2-lambda-functions-closures-presentation)
"Object Orientation
Lambda Functions are Closures because they automatically get bound to the scope of the class that they are created in. '$this
' is not always needed in the scope.
Removing '$this
' can save on memory.
You can block this behaviour by declaring the Lambda Function as static."
Что не так с этим кодом?
Я получаю эту ошибку:
Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' in C:\wamp\www\z-final\a.php on line 11
Почему эта строка кода не работает? Return static function () {var_dump ($ this);}; & quot; ?
class foo
{
public function getLambda()
{
return function(){var_dump($this);};
}
public function getStaticLambda()
{
return static function(){var_dump($this);};
}
}
$foo = new foo();
$lambda = $foo->getLambda();
$staticLambda = $foo->getStaticLambda();
$lambda();
$staticLambda();