Re: [PATCH] [RFC] Closures and lambda functions in PHP
| From: | Dmitry Stogov | Date: | Fri, 27 Jun 2008 14:49:57 +0000 |
| Subject: | Re: [PATCH] [RFC] Closures and lambda functions in PHP | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-38657@lists.php.net to get a copy of this message | ||
I thought about use($this) too. :)
I'll try to implement it in the next version of the patch.
Thanks. Dmitry.
Alexander Wagner wrote:
> On Friday 27 June 2008, Andi Gutmans wrote:
>> I lean towards the use(...) syntax.
>
> Me too.
>
>>> * I provided a patch variant that only stores $this if $this is
>>> explicitely used inside a closure [..]
>> Safest not to take shortcuts. You get yourself into trouble with things
>> which will stop working. -1 on this optimization.
>
> I believe that always implicitly referencing $this is a mistake.
> Not only does it turn every lambda that is created inside an object into a
> heavier closure, it also makes it impossible for the closure to outlive the
> object, which can, in some rare cases, dramatically increase memory
> consumption, in which case things will also stop working.
> Also, given how many people put all their code into classes, this may cause
> problems more often than we might think, although the wasted memory will
> usually go undetected, making this whole thing a source for nasty heisenbugs.
>
> If the optimization of only referencing $this when it is actually used is a
> dangerous shortcut, the alternative should be to not implicitly reference
> $this at all and require it to be importet through "use ($this)".
>
>>> * Do you want closures in PHP?
>> I think most people here feel it's useful or are at least indifferent.
>
> There are those who want them and those who don't know that they want them.
>
> Gesundheit
> Wag
>