Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59869 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50495 invoked from network); 13 Apr 2012 09:57:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2012 09:57:52 -0000 Authentication-Results: pb1.pair.com header.from=verbitsky_alexandr@mail.by; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=verbitsky_alexandr@mail.by; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain mail.by designates 193.232.92.17 as permitted sender) X-PHP-List-Original-Sender: verbitsky_alexandr@mail.by X-Host-Fingerprint: 193.232.92.17 post.open.by Received: from [193.232.92.17] ([193.232.92.17:55313] helo=post.open.by) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/D2-35770-F98F78F4 for ; Fri, 13 Apr 2012 05:57:52 -0400 Received: from [86.57.155.126] (account verbitsky_alexandr@mail.by HELO a-verbitsky.IV) by post.open.by (CommuniGate Pro SMTP 4.3.12) with ESMTPSA id 122159362 for internals@lists.php.net; Fri, 13 Apr 2012 12:57:48 +0300 Message-ID: <4F87F890.2000501@mail.by> Date: Fri, 13 Apr 2012 12:57:36 +0300 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: internals@lists.php.net References: <4F87DF77.7040608@mail.by> <4F87E595.2090704@sugarcrm.com> In-Reply-To: <4F87E595.2090704@sugarcrm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Allow "use( $longname as $alias)" syntax for closures declaration From: verbitsky_alexandr@mail.by (Verbitsky Alexander) 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) ...