$ php --version
PHP 5.5.4 (cli) (built: Sep 19 2013 17:10:06)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
The following code (similar to example at https://bugs.php.net/bug.php?id=49543):
class Foo
{
public function bar()
{
return function() use ($this)
{
echo "in closure\n";
};
}
}
fails with:
PHP Fatal error: Cannot use $this as lexical variable
Yet according to the PHP docs and a comment on that bug report from Rasmus Lerdorf, using $this in anonymous functions was added as of PHP 5.4. What am I doing wrong?