On Thu, Apr 12, 2012 at 6:25 PM, Laruence <larue...@php.net> wrote:
> Now you can not use $this
>
>      class foo {
>           public function bar() {
>               return function() use ($this) {  // PHP Fatal error:
> Cannot use $this as lexical variable
>               }
>           }
>      }
And it is good that you can't - as of PHP 5.4 the $this variable is
automatically bound, unless the closure is declared `static`. Adding a
possibility to alias $this could get really messy imho. With the
auto-binding the behavior is clear, but with the $this as $that syntax
several questions open up: a) Is $this the object as the public sees
it? I.e. the same as with the manual $that = $this assignment. Or does
it also expose private properties? b) If you use &$this as $that, will
$that automatically be rebound to the class it is used in?

Nikita

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to