Hi,
I would be fine with requiring an explicit declaration of $this if it helped
avoid memory leaks.
I would propose to always require explicit declaration of $this, even if there
is no memory-leak problem. This would make it easier to distinguish plain
lambdas from closures and would prevent closures from being created by
accident.
I believe that is not neessary: $this is not a normal variable in PHP
(see for example <http://bugs.php.net/bug.php?id=33652> or
<http://bugs.php.net/bug.php?id=43163>) but a language construct. So it
is possible to determine if this is used at compile time (if $this is
used inside the function, op_array->this_var != -1 if I'm not mistaken)
- and therefore automatically importing it (it is automatically
available in local scope of class methods anyway). The only possible
clash could be nested lambdas - but there you could simply enforce the
creation of $this in all functions containing a lambda which uses $this).
To sum it up: I believe it is possible to optimize it that way that
$this is only stored within the closure if the closure actually needs it
- but without the need for declaring it explicitly.
Regards,
Christian
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php