Re: [RFC] Allow "use( $longname as $alias)" syntax for closures declaration

From: Date: Fri, 13 Apr 2012 08:36:37 +0000
Subject: Re: [RFC] Allow "use( $longname as $alias)" syntax for closures declaration
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-59863@lists.php.net to get a copy of this message
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. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

« previous php.internals (#59863) next »