On Jun 18, 2008, at 11:01 AM, Stanislav Malyshev wrote:
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 it
You 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.
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.
-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php