Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38310 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43735 invoked from network); 17 Jun 2008 05:57:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2008 05:57:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=quickshiftin@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=quickshiftin@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.220.153 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: quickshiftin@gmail.com X-Host-Fingerprint: 72.14.220.153 fg-out-1718.google.com Received: from [72.14.220.153] ([72.14.220.153:56682] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3B/E8-18128-B3257584 for ; Tue, 17 Jun 2008 01:57:16 -0400 Received: by fg-out-1718.google.com with SMTP id 16so3814828fgg.23 for ; Mon, 16 Jun 2008 22:57:12 -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:references; bh=FGEyg6trMdtGXq+ePTiIDRRrj1ISg2ftoOuYEemnx10=; b=Rkagnm6datj9zsUGB/IzdasoRFqyvpVMPr4Y/uxDS0D1weIIlQfJg8PFxFPlhmPQZd w9F+Ma04K/bG6P46P/sHeHztoq7Vm2LNJF614pLxvTjoeyu7FqO9t2nKnDdeLUOGiwTo i3hnazX8Hl4OEVbuc4kCtEWOhxPOTzuTXvyks= 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:references; b=p5QD7/qP1CWLaVcoqOm7mVDxc4Fx+6z6MFjl+qBojsurOpWli7lVgyIW+bgeWGy0st 2Gne+mfW15n+HVc4cf/ZXy1AlcAyluNqdjyg1lgW0ZdEMGtu4WAHNtXOWVlsPJipgRhj 51u+/zZhHG9an8n55k6QflhEV/sKkrFR9D3m4= Received: by 10.86.79.19 with SMTP id c19mr8698642fgb.52.1213682232493; Mon, 16 Jun 2008 22:57:12 -0700 (PDT) Received: by 10.86.33.3 with HTTP; Mon, 16 Jun 2008 22:57:12 -0700 (PDT) Message-ID: <7dd2dc0b0806162257t15f679c1t2d9e77221144f340@mail.gmail.com> Date: Mon, 16 Jun 2008 23:57:12 -0600 To: "Larry Garfield" Cc: internals@lists.php.net In-Reply-To: <200806162257.24141.larry@garfieldtech.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1284_28572515.1213682232543" 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: quickshiftin@gmail.com ("Nathan Nobbe") ------=_Part_1284_28572515.1213682232543 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Jun 16, 2008 at 9:57 PM, Larry Garfield wrote: > Thoughts from a user-land denizen: > > - Related to that, would it then be possible to add methods to a class at > runtime using lambda functions as the added methods? If so, how? If not, > is > that something that could reasonably be added here without hosing > performance > (or at least doing so less than stacking __call() and > call_user_func_array() > does)? im curious about this as well, and i would welcome such functionality. adding methods to class instances from within the definition of the class seems intuitive, the $this keyword should be available, but when adding methods via a variable which holds a handle to a class instance, well, i wonder, would the $this keyword be available within those anonymous function definitions? class Dynamic { private $someVar = 5; /// adding a function to instances from within the class public function addMethodAtRuntime() { $this->dynamicFunc1 = function() { return $this->someVar; // expected to work } } } /// adding a function to an instance externally $dynamic = new Dynamic(); $anotherVar = 6; $dynamic->dynamicFunc2 = function() { lexical $anotherVar; // expected to work return $this->someVar + $anotherVar; // would this work ? } /// invoking dynamically added methods /// (anticipated behavior given above definitions) $dynamic->addMethodAtRuntime(); echo $dynamic->dynamicFunc1(); // 5 echo $dynamic->dynamicFunc2(); // 11 -nathan ------=_Part_1284_28572515.1213682232543--