Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34074 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43105 invoked by uid 1010); 18 Dec 2007 03:28:28 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 43090 invoked from network); 18 Dec 2007 03:28:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Dec 2007 03:28:28 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.30.48 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.30.48 qmta05.emeryville.ca.mail.comcast.net Received: from [76.96.30.48] ([76.96.30.48:46172] helo=QMTA05.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/54-06889-B5E37674 for ; Mon, 17 Dec 2007 22:28:28 -0500 Received: from OMTA05.emeryville.ca.mail.comcast.net ([76.96.30.43]) by QMTA05.emeryville.ca.mail.comcast.net with comcast id S3GW1Y0080vp7WL0A02g00; Tue, 18 Dec 2007 03:28:31 +0000 Received: from earth.ufp ([71.228.13.89]) by OMTA05.emeryville.ca.mail.comcast.net with comcast id S3UW1Y0081vH2xB8R00000; Tue, 18 Dec 2007 03:28:31 +0000 X-Authority-Analysis: v=1.0 c=1 a=ZN6zT4ptW18A:10 a=wXT3aEviyEA-lI7OxFIA:9 a=m9AEFzNtXAT5_M41duoA:7 a=aAwzUMjnlbpSQ_5Iy1znK4OL86EA:4 a=FHBbIDN7CdwA:10 a=iSkjo3vVhZYA:10 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id E74AAD834C for ; Mon, 17 Dec 2007 21:28:23 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tDXP-r5lA0yl for ; Mon, 17 Dec 2007 21:28:23 -0600 (CST) Received: from vulcan.ufp (vulcan.ufp [192.168.42.4]) by earth.ufp (Postfix) with ESMTP id B8C98D8338 for ; Mon, 17 Dec 2007 21:28:13 -0600 (CST) To: internals@lists.php.net Date: Mon, 17 Dec 2007 21:30:08 -0600 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) References: <98b8086f0712150818n40056cedyf0aae7a5a08a27b7@mail.gmail.com> <476582E6.7020808@zend.com> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200712172130.08216.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Re: PATCH: anonymous functions in PHP From: larry@garfieldtech.com (Larry Garfield) Let me see if I'm understanding you correctly, because that sounds like the line I'd been thinking along. ---------- function baz() { $var = 5; $foo = function($a, $b) { lexical $var; return $a + $b + $var; } return $foo; } $func = baz(); function bar($func) { return $func(2, 3); } echo bar($foo); // prints 10 ---------- Right? Would it be possible to push the heavy lifting onto the compiler rather than runtime in the above case? I'm assuming that making the function above GC-able would be a herculean task at this point, based on previous comments, but I do not actually know myself. On Monday 17 December 2007, Jeff Moore wrote: > Hello, > > Reading the prior discussion, I think either $_SCOPE['x'] or the > lexical $x syntax is fine for accessing local variables in the > enclosing scope. But closures also should also support $this and > static:: when the closure is defined in a method. > > I think a solution for closures should add a new variable type. That > way, the code can compiled at compile time, while the enclosing > context (local variables plus $this for methods) can be captured at > run time in the new variable type. Also, when the closure value is > garbage collected, the references to the enclosing scope and object > instance can also be freed. > > Additionally, the callback psuedo-type could be promoted to the new > type, with the string or array representation converted when > required. It wouldn't be necessary, but a callback literal along the > lines of Array() could also be added to make the conversion > unnecessary. I find the following to be easier to understand: > > set_error_handler(Callback("foo")); > > Than > > set_error_handler("foo"); > > The current syntax would still work because of automatic type > conversion. > > Best Regards, > > Jeff -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson