Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28452 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24963 invoked by uid 1010); 19 Mar 2007 21:34:59 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 24948 invoked from network); 19 Mar 2007 21:34:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2007 21:34:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=ceo@l-i-e.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ceo@l-i-e.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain l-i-e.com from 67.139.134.202 cause and error) X-PHP-List-Original-Sender: ceo@l-i-e.com X-Host-Fingerprint: 67.139.134.202 o2.hostbaby.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from [67.139.134.202] ([67.139.134.202:2179] helo=o2.hostbaby.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/F3-01604-1020FF54 for ; Mon, 19 Mar 2007 16:34:58 -0500 Received: (qmail 39293 invoked by uid 98); 19 Mar 2007 21:34:58 -0000 Received: from 127.0.0.1 by o2.hostbaby.com (envelope-from , uid 1013) with qmail-scanner-1.25 (clamdscan: 0.88.7/2871. Clear:RC:1(127.0.0.1):. Processed in 0.082328 secs); 19 Mar 2007 21:34:58 -0000 X-Qmail-Scanner-Mail-From: ceo@l-i-e.com via o2.hostbaby.com X-Qmail-Scanner: 1.25 (Clear:RC:1(127.0.0.1):. Processed in 0.082328 secs) Received: from localhost (HELO l-i-e.com) (127.0.0.1) by localhost with SMTP; 19 Mar 2007 21:34:58 -0000 Received: from 216.230.84.67 (SquirrelMail authenticated user ceo@l-i-e.com) by www.l-i-e.com with HTTP; Mon, 19 Mar 2007 16:34:58 -0500 (CDT) Message-ID: <32945.216.230.84.67.1174340098.squirrel@www.l-i-e.com> In-Reply-To: <0757BDEA-65F5-4123-B647-060DCA84B4B0@omniti.com> References: <86478A67-DCA2-4000-9EF0-DA4338E8389B@omniti.com> <45FDF031.4010508@zend.com> <45FE2312.1050506@zend.com> <45FED6D9.8030307@caedmon.net> <45FEDAE5.2010309@zend.com> <45FEE396.7040905@caedmon.net> <0757BDEA-65F5-4123-B647-060DCA84B4B0@omniti.com> Date: Mon, 19 Mar 2007 16:34:58 -0500 (CDT) To: "Wez Furlong" Cc: "Sean Coates" , "Stanislav Malyshev" , internals@lists.php.net Reply-To: ceo@l-i-e.com User-Agent: Hostbaby Webmail MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] PATCH: anonymous functions in PHP From: ceo@l-i-e.com ("Richard Lynch") On Mon, March 19, 2007 2:33 pm, Wez Furlong wrote: > I've been thinking about this on and off today too. > Something along the lines of the following is more in the PHP spirit: > > $ver = phpversion(); > $fancyVer = function () { lexical $ver; return "PHP $ver"; }; > > Where "lexical" is a keyword that means "inherit this variable from > the current lexical scope". I'm not suggesting that this is a good > name for the keyword, it's just something that springs to mind. I believe "Environment" is what it was called back in CLOS when we schlepped it around as an extra extra argument to functions that needed data from outside function scope... > So, given some way to explicitly reference the scope where the > function was "defined", what happens when you call $fancyVer after > that scope has gone away: > > function doSomething() { > $ver = phpversion(); > return function () { lexical $ver; return "PHP $ver"; }; > } > $func = doSomething(); > $func(); # the doSomething() scope (hash table) doesn't exist any more > > This could perhaps be solved by taking a reference to $ver when the > function is bound, but I don't know enough about the ZE to understand > the implications of that; it would probably require a bit more state > tracking per zend_function so that we know that we need to do that > step during binding. This gets incredibly complex not only to figure out what to do in the PHP source, but for scripters to figure out what the heck it does... If it's making YOUR head spin, what will it do to the poor unwashed masses?... Obviously, an anonymous function is going to be inherently complex -- but keep it as simple as it can be. I suspect that you could get away with JUST using global and/or static as they exist now, not introduce yet another scoping keyword, and anything that *NEEDS* to be done with an anonymous function can be done. Does anybody really *NEED* a variable whose scope is non-global and captured at the time of the func definition, carried over beyond the scope of that until it's executed?... Somehow I think you're just complicating it "because you can" rather than because anybody really NEEDS this. You have to have a pretty esoteric function to need that kind of scope control, no? -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?