I'm trying to learn PHP, and now I'm stuck in 'static anonymous function'.
I found this in a tutorial (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."
What is wrong with this code?
I get this error:
Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' in C:\wamp\www\z-final\a.php on line 11
Why this code line doesn't work "return static function(){var_dump($this);};" ?
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();
statickeyword betweenreturnandfunction()is the problem, what did you tried to achieve?