Why can I not use $this as a lexical variable in PHP 5.5.4?

So it seems $this can be used simply if it isn’t specified via the “use” keyword.

The following echoes ‘bar’:

class Foo
{
    private $foo = 'bar';

    public function bar()
    {
        return function()
        {
            echo $this->foo;
        };
    }
}

$bar = (new Foo)->bar();

$bar();

This was reported in the php-internals mailing list and is apparently overhang from 5.3’s lack of support for this functionality:

http://marc.info/?l=php-internals&m=132592886711725

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)