Re: [PATCH] [RFC] Closures and lambda functions in PHP
| From: | Stanislav Malyshev | Date: | Wed, 18 Jun 2008 15:01:32 +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-38350@lists.php.net to get a copy of this message | ||
Hi!
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.
there, repeat as necessary. Once found outside the closure's scope, something similar to the proposed "lexical" keyword happens. Closureslexical in the proposal binds to creator's scope, not caller's scope, as I understood. Anyway, binding to caller's immediate scope doesn't seem that useful since you could just pass it as a parameter when calling. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com