Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38448 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45152 invoked from network); 20 Jun 2008 08:36:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2008 08:36:29 -0000 Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:40433] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5F/D4-16112-D0C6B584 for ; Fri, 20 Jun 2008 04:36:29 -0400 Received: from MBOERGER-ZRH (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id B083F11F161; Fri, 20 Jun 2008 10:36:26 +0200 (CEST) Date: Fri, 20 Jun 2008 10:36:26 +0200 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <871378260.20080620103626@marcus-boerger.de> To: "Andi Gutmans" CC: "Christian Seiler" , "php-dev List" In-Reply-To: <698DE66518E7CA45812BD18E807866CE01B70F8E@us-ex1.zend.net> References: <4856A547.3080801@gmx.net> <698DE66518E7CA45812BD18E807866CE01B11811@us-ex1.zend.net> <4858FCC7.5030305@gmx.net> <698DE66518E7CA45812BD18E807866CE01B70D73@us-ex1.zend.net> <48596C9E.2080605@gmx.net> <698DE66518E7CA45812BD18E807866CE01B70F8E@us-ex1.zend.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: helly@php.net (Marcus Boerger) Hello Andi, Thursday, June 19, 2008, 8:44:07 AM, you wrote: > See below: >> -----Original Message----- >> From: Christian Seiler [mailto:chris_se@gmx.net] >> Sent: Wednesday, June 18, 2008 1:14 PM >> To: php-dev List >> Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP >> >> Frankly, I don't really see a problem with using references. It fits >> into what's already there in PHP and it assures that closures have the >> necessary properties to make them useful. > I think you are right that there isn't really a good alternative as the > "parent" scope does not necessarily exist anymore. Your solution is likely the best. I though we are speaking of PHP here? And all I remeber is that PHP has reference counting. So it doesn't matter if we do reference or value binding. We simply have to increase the internal reference counter - done. > >> >> - Please check eval(). I assume it will bind to global scope but >> >> let's just make sure what happens esp. when it's called from within >> >> a method... >> >> Hmm, closures inside eval() will bind variables to the scope in which >> eval() was called. But closures defined inside eval will NOT be class >> methods, even if eval() is called within a class. >> >> But I do find that behaviour consistent with what PHP currently does >> with normal functions and variables: If eval()'d or include()'d inside a >> function, variables will the "global scope" of eval() or the included >> file will actually be the local function scope whereas defined functions >> inside will automatically become global functions. >> >> Of course, this behaviour should be documented but I don't see a reason >> to try and change it. > I agree. It behaves as I would expect I just wanted to make sure you > verify that because I didn't have the opportunity to do so. You'd > actually have to work very hard for it not to behave in that way :) Let's > just make sure we have unit tests for both cases just so we have a good regression on this one. >> >> - In PHP 5, object storage is resources done right. I don't think >> >> we should be using the resource infrastructure for this >> >> implementation and would prefer to use the object one. It's better. >> >> I suggest to take a look at it. >> >> Hmm, seems like a good idea. If nobody objects in the next few days, >> I'll rewrite my patch to use objects instead of resources. What class >> name do you suggest? > Great. I think Closure is probably a good name. > [Btw, if we want to get fancy we could even have a __toString() method > on those which would print out information about the Closure. But this is > not a must, just something which eventually could be nice for debugging purposes...] >> PS: Somebody made me aware of a segfault in my code when destroying the >> closure variable while still inside the closure. I'll fix that. > :) > Thanks, > Andi Best regards, Marcus