Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42708 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36811 invoked from network); 19 Jan 2009 17:05:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2009 17:05:18 -0000 Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.116 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 63.205.162.116 us-gw1.zend.com Windows 2000 SP4, XP SP1 Received: from [63.205.162.116] ([63.205.162.116:34568] helo=us-gw1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C0/3F-50097-CC2B4794 for ; Mon, 19 Jan 2009 12:05:17 -0500 Received: from [192.168.27.21] ([192.168.27.21]) by us-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 19 Jan 2009 09:06:08 -0800 Message-ID: <4974B2C8.5000704@zend.com> Date: Mon, 19 Jan 2009 09:05:12 -0800 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: Marcus Boerger CC: Ionut Gabriel Stan , internals@lists.php.net References: <1016989528.20090112233204@marcus-boerger.de> <496BCD33.4080703@zend.com> <133861245.20090113225847@marcus-boerger.de> <496D2074.3070303@zend.com> <496DD269.4050701@gmail.com> <496E12CE.2080403@zend.com> <1956503865.20090117212630@marcus-boerger.de> <49743A89.3070607@zend.com> <995073772.20090119125721@marcus-boerger.de> In-Reply-To: <995073772.20090119125721@marcus-boerger.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 19 Jan 2009 17:06:08.0223 (UTC) FILETIME=[389C06F0:01C97A58] Subject: Re: [PHP-DEV] [RFC] prototyping From: stas@zend.com (Stanislav Malyshev) Hi! > class Foo { > private $myVeryOwnData; > function bla { > $this->bigMEss = function () { return $this->myVeryOwnData; } > } > } This is not a "mess" - this is *exactly* what closures are for. If you don't want this function to be able to access private variables - do not put code that accesses private variables there! That's like saying this code is a "mess": class Foo { private $myVeryOwnData; public function getData() { return $this->myVeryOwnData; } } because you can do this: $a = new Foo(); echo $a->getData(); Oh horror!! It accessed private data!! Because you explicitly told it to access it, yes. What did you expect if you provide public method to access private data? > // I am very sorry but I would expect the closure to rebind $this as > // $this always points to the bound object. And how is this different? I am very sorry but your expectation is wrong. There's no reason for closures to magically rebind, and if some particular language, due to limitations of its design, has this weird WTF inside, it's a problem that we don't have to carry on into PHP. If you created a closure, you got context. That's the whole point of closure. $this is part of the context. If for some reason you need WTF-closures that keep half of the context from where they were created and half from where they were called, you may create it, but regular closures shouldn't do that. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com