Re: [PATCH] [RFC] Closures and lambda functions in PHP
| From: | Gwynne Raskind | Date: | Wed, 18 Jun 2008 16:32:38 +0000 |
| Subject: | Re: [PATCH] [RFC] Closures and lambda functions in PHP | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-38356@lists.php.net to get a copy of this message | ||
On Jun 18, 2008, at 11:01 AM, Stanislav Malyshev wrote:
This lookup happens at the time the closure is first declared, and the value is stored for later use by the closure; the calling scope doesn't need to exist anymore. The problem with going to the top of the stack is an issue, though; the Lua interpreter's idea of "scope" is rather different from PHPs, and it's not nearly the same penalty there.The Lua interpreter handles this by resolving variable references as they're made; "someVariable1" is looked up in the closure's scope and not found, so the interpreter steps out one scope and looks for itYou may get into a problem here - creator's scope may not exist when you execute the closure, and using caller's scope would be very unexpected - usually closures are intended to capture part of creating environment, not calling environment. It would also impose serious penalty if you just use undefined variable - you'd have to go through whole stack up to the top.
-- Gwynne, Daughter of the Code "This whole world is an asylum for the incurable."