Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46125 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74458 invoked from network); 20 Nov 2009 09:49:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Nov 2009 09:49:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=ithinkihaveacat@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ithinkihaveacat@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.44 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ithinkihaveacat@gmail.com X-Host-Fingerprint: 209.85.160.44 mail-pw0-f44.google.com Received: from [209.85.160.44] ([209.85.160.44:52956] helo=mail-pw0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/9A-04175-E36660B4 for ; Fri, 20 Nov 2009 04:49:51 -0500 Received: by pwj15 with SMTP id 15so2137707pwj.23 for ; Fri, 20 Nov 2009 01:49:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type; bh=BdFh101U7ZuFhG1N1mY2XSvAgHJs69/LUsDvJDCN68Q=; b=Z0FFmvK+BpLU41mfSUCwXcAtG4tSi/cGPCdcsAeVb1vU4BC3NOJu6Lup4eZcfQbTWZ /pnQtimxxT3iHqA1ArVWmyy/bjYEaNo16KMW8Dn9uKe7eW3Erz8T9tU2NYpl0U8hKP9g hvhf68JEeA1yu2M5x1EHmqnMfQsLFNzjsQ6FA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=dhyS85xrbcdc9m8RxHsr6mPjPStTUiRUX1mBatu3lrlgMlIsKbL1PiJpveM1RFVNVL popAKG1M6EB4SAq5F9/6Z1xshDSGBGGw6rcvPMKjtwReAhTwL++kDVYbwYb5jmUZJ0Ji hAv5gtAGFGe7O+TznuNtwd3u+KSgS2uNNr2Ng= MIME-Version: 1.0 Sender: ithinkihaveacat@gmail.com Received: by 10.141.50.12 with SMTP id c12mr17623rvk.140.1258710586388; Fri, 20 Nov 2009 01:49:46 -0800 (PST) In-Reply-To: References: <4B01A4C2.8030602@gmx.net> <4B0273E5.9000606@easyflirt.com> <4B02D7FA.3080206@easyflirt.com> Date: Fri, 20 Nov 2009 09:49:46 +0000 X-Google-Sender-Auth: a4c354c629e94f38 Message-ID: <140eba4e0911200149ic5a57dem166943db57d1d642@mail.gmail.com> To: Jelrik van Hal Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Closures and $this From: mjs@beebo.org (Michael Stillwell) On Thu, Nov 19, 2009 at 4:29 PM, Jelrik van Hal wrote: > Victor, I do wholeheartedly agree with you about the mess things will be > when allowing $this to refer to different things in different contexts of > calling the same closure (B, C and D): I think it'll prove very difficult to > keep track of which call will end up doing exactly what in which > environment. I think any mechanism for rebinding $this (whether automagical or explicit) will be too, well, weird. I can imagine a system of rebinding $this being both consistent and useful, but it adds too much complexity: to understand what's going on, you not only need to understand closures, but you need to know how they interact with PHP's OO system, you need to know what rebinding is (it doesn't happen anywhere else that I can think of), and you need to know how the rebinding system works. JavaScript's approach actually fairly confusing--and this is despite the fact that the language has always had it. > Also, I'm wondering why people think there should be a $this inside a > closure. As stated in the RFC/Wiki, closures are not thought out to be used > alongside OO-code. Why would we want to couple them? I see the use of > closures, but not as OO-related tools using $this. What is the problem with > proposal (0), leaving it as it is now? I do think it would be nice if function() use ($this) { ... } worked, and bound $this in the same way that it bound any other variable, instead of producing "Cannot use $this as lexical variable". This would eliminate the need to do: $obj = $this; $fn = function() use ($obj) { // use $obj as if it were $this } Was this how things used to work, before http://wiki.php.net/rfc/closures/removal-of-this happened? Michael -- http://beebo.org