Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38309 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36518 invoked from network); 17 Jun 2008 04:59:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2008 04:59:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.46.29 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: indeyets@gmail.com X-Host-Fingerprint: 74.125.46.29 yw-out-2324.google.com Received: from [74.125.46.29] ([74.125.46.29:9358] helo=yw-out-2324.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 83/C7-18128-59447584 for ; Tue, 17 Jun 2008 00:59:01 -0400 Received: by yw-out-2324.google.com with SMTP id 5so2934725ywb.83 for ; Mon, 16 Jun 2008 21:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=WOFW18VYfI640frlAT9nWoeUcYV179v8Cw99RObxsVw=; b=WaKeOEFHnNeItMcCy+ycT51KraE1/UzNHUbbOYjEBStOI+OP0f+AC3Rk5OR0BBdsma 9NH8+tmL3NDYhX8qCKPNREUnSphTsLVTU88WxbcHvKrJ3rK+Mi777cHmVYyyYpkCXoC9 QNZDW5DOjOIdC1zZuw3qsCr8mFhwxYijPz8Cw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=ZR/yOcOTI9pNGEDAPQyrdm8aayNIiPgjgZ2WOjPk64FHlKDHc2dCa+rldIJSRuO784 vY3qCPrdAvECeWUjV4myHc9pBos8PA6V68fKs6udnum/fi9oA51J+11QeQgFw9mAkuTY uCScLfG57M7YtUgTBqempoCEzwGq10ONnL3gA= Received: by 10.151.154.12 with SMTP id g12mr10848144ybo.165.1213678738482; Mon, 16 Jun 2008 21:58:58 -0700 (PDT) Received: by 10.150.158.8 with HTTP; Mon, 16 Jun 2008 21:58:58 -0700 (PDT) Message-ID: Date: Tue, 17 Jun 2008 08:58:58 +0400 To: "Larry Garfield" Cc: internals@lists.php.net In-Reply-To: <200806162257.24141.larry@garfieldtech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4856A547.3080801@gmx.net> <4856B752.1040500@gmx.net> <200806162257.24141.larry@garfieldtech.com> Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: indeyets@gmail.com ("Alexey Zakhlestin") On 6/17/08, Larry Garfield wrote: > - I am a little confused about the OOP interaction. How does a function > become a public method of the class? > > class Example { > private $a = 2; > > function myMethod($b) { > $lambda = function() { > lexical $b; > return $this->a * $b; // This part I get > }; > return $lambda; > } > } > > $e = new Example(); > $lambda = $e->myMethod(); > $e->$lambda(5); > > That doesn't seem right at all, but that's how I interpret "Essentially, > > closures inside methods are added as public methods to the class that > > contains the original method." Can you give an example of what that actually > means? As far as I understand, it means following: class Example { private $a = 1; private function b() { return 2; } public function getLambda($param) { $lambda = function($lparam) { lexical $param; return $this->a + $this->b() + $param + $lparam; } return $lambda; } } $obj = new Example(); $lambda = $obj->getLambda(3); $result = $lambda(4); // 1+2+3+4 => 10 -- Alexey Zakhlestin http://blog.milkfarmsoft.com/