Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61485 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74540 invoked from network); 19 Jul 2012 14:13:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 14:13:19 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.216.49 mail-qa0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:65402] helo=mail-qa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/39-25752-EF518005 for ; Thu, 19 Jul 2012 10:13:19 -0400 Received: by qabj40 with SMTP id j40so1893488qab.8 for ; Thu, 19 Jul 2012 07:13:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=HfkdAZu9Oe+nX3bECM0r2iMhVHDqL+5iOVjVWDv3oaY=; b=W8S5ytqPNANCQsO3KUzs0V4a0OX9zYiyQ6dzx01GHJ0TEsnPIwsfn01PM7DBG6PrVF KvyGakUUZYHVX6uN7HM0/LaC949W4yF/TnDZUI5COFMJH5LTwhqFiwoVRWsK7L6ITOAI q2NC9Jnz73ZHxaqNw67t7J/YQI0OI5Pfx5maEH3j707w14g22GmHuaiBJtXnPleEWdhb /ILAQTCowdn0uwLZ3xk40J2Hhx1QF1hpq/8vSXfkBlDcAEF550hL/7PC4c5LRwcb1J4r j/70lr3dgipGftRfID1clUlqIvrPMsGUt/uy4hJtQt4dZ4iKLywx9mvJaofWfkibezty nohg== MIME-Version: 1.0 Received: by 10.224.185.20 with SMTP id cm20mr4007683qab.53.1342707195418; Thu, 19 Jul 2012 07:13:15 -0700 (PDT) Received: by 10.229.182.4 with HTTP; Thu, 19 Jul 2012 07:13:15 -0700 (PDT) In-Reply-To: References: Date: Thu, 19 Jul 2012 10:13:15 -0400 Message-ID: To: Laruence Cc: Nikita Popov , PHP Internals Content-Type: multipart/alternative; boundary=20cf30334fad6b96ac04c52f6183 Subject: Re: [PHP-DEV] Call for voting: [RFC] Allow use T_AS in closure use statement From: ircmaxell@gmail.com (Anthony Ferrara) --20cf30334fad6b96ac04c52f6183 Content-Type: text/plain; charset=ISO-8859-1 Laruence, On Wed, Jul 18, 2012 at 9:53 PM, Laruence wrote: > Hi: > I saw you two vote against for this RFC. > > could you explain why? then maybe I can improve it. > > thanks The reason that I voted against it is simple. It's sugar to make it harder to understand what the code is doing, and blur the line of what the closure is doing. Closures are supposed to "wrap" a parent scope (in other words, "close in on it"). The closure isn't a strictly new scope, but an extension on the existing one. PHP muddied this concept with the USE declaration (rather than importing the parent scope in its entirety, as almost every other language does). But this change would muddy it even further. My argument would be that if you really need to rename variables for clarity, you don't belong putting it in a closure in the first place (as it's way too much logic that needs to be split out into a separate function entirely). Additionally, it will further confuse the subject because: $f = function() use ($this as $obj) { $obj->protectedMethod(); // fatal error, as it's not in the same scope } That will fail for non-obvious reasons. At least currently there's an extra level of indirection required to pass $this, so it's a little bit clearer that you're not passing `$this` to the object, but a copy of it. Additionally, we need to think about the coupling between the closure's scope and the parent scope. There is -by design- very tight coupling between them. And not even from a language level. The closure is defined *inside* of another function, at a specific point in execution to use certain aspects of the parent scope. That means that it's highly coupled to the parent function. Actually, it's has cohesion in almost all forms: Logical, Temporal, Procedural, Communicational, Sequential and Functional. The only form of cohesion that it doesn't directly and automatically have is Coincidental... Therefore, their scopes are always going to be tightly coupled (which is what we want with a closure). If you really need to rename variables into the closure, create a factory for the closure: $closureFactory = function ($a, $b, $c) { return function() use ($a, $b, $c) { }; }; Yes, it's an extra level of indirection, but that indirection is explicit rather than implied.... So, I guess in summary, I would say that I voted against it because it further blurs the line between what a closure is and what PHP implements (which is already fairly blurry). That's my $0.02 at least... Anthony --20cf30334fad6b96ac04c52f6183--