On 04/13/2012 11:36 AM, Stas Malyshev wrote:
Hi!

I'm at a bit of a loss as to why Laruence is claiming that allowing
closures to implicitly access variables in the outer scope requires
duplicating the symbol table.
Because variables need to be stored somewhere after the parent function
exits.

Is there any technical reason why it's not possible for scopes to retain a
pointer to their parent scopes so variables can be looked up that way?
Because the parent scope will be gone by the time closure is called.
Unless we retain a copy of it - which in most cases is very expensive
and impractical - you usually don't need all variables from parent scope
- you need 1-2 of them, keeping all of them linked to the closure - and
thus not freed until closure ceases to exist - would be very expensive.
Declaring shared variables explicitly is a trade-off allowing you to not
keep all the variables in case you do not need them.

I am not sure but it is too expensive only for memory. I don't think that current scope will be very big and operation for copying it very slowing because we work with memory (correct me if i not right). Often we don't to know what variables will be needed in future. And seems to me that can to detect which variables bound in closure and copy only it. Many people use PHP not because it very fast and because it very simple to use. Syntax must be more clear for support. And using additional keyword for a bound with variables it's not doing it.

At now this is there should not alter of course. What really needed is 'named parameters'

For example

function some_action($var1 = 0, $var2 = 0) ...

If need pass only second parameter i need to do following

some_action(0, $b) ...

Instead of

some_action($var2 = $b) ...


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to