Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45583 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58914 invoked from network); 17 Sep 2009 09:10:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2009 09:10:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.220.226 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 209.85.220.226 mail-fx0-f226.google.com Received: from [209.85.220.226] ([209.85.220.226:44868] helo=mail-fx0-f226.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/C9-29403-8FCF1BA4 for ; Thu, 17 Sep 2009 05:10:17 -0400 Received: by fxm26 with SMTP id 26so131522fxm.23 for ; Thu, 17 Sep 2009 02:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=TxZ5dI9MUtrgGpPhF0sv8bwMl90NAnuu75us2M+zFm0=; b=WGq33Wt983RJFlT46WqsuoGd2JzxIDV075vU8q3iPbGh1Hg19sWnE/VVEWulZ/C9sC 2Tl9h3uxEDZDfU8YPohP17xmn6IP8iN085vIsaJmtcTzGS0nzdKllFGajgLwYIFPK+8T LrHpcCrl8kC31mPe5luNGSHwaiMKoC0c8T7BM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; b=Nm+dtbNsdisLfu1JbrSB6ouzgKlLTc6PyK0GQOtyyozp5a5NfTdYzylnPLpB5wn9wW 4m19sQOr66ifisKf5CJWBx0P2PYGFI6UOSo4qOuPim+CICIYZvwXqxzqj+a2BbApVpB3 94z/ctSL1pAkxLirvz2bUVIULpHt3JpBIMiIM= MIME-Version: 1.0 Received: by 10.223.92.153 with SMTP id r25mr3361639fam.99.1253178613567; Thu, 17 Sep 2009 02:10:13 -0700 (PDT) Reply-To: RQuadling@googlemail.com In-Reply-To: <7F7F9F17-A755-428B-93A6-1E0AFA20DE50@csisd.org> References: <7F7F9F17-A755-428B-93A6-1E0AFA20DE50@csisd.org> Date: Thu, 17 Sep 2009 10:09:52 +0100 Message-ID: <10845a340909170209s277d1291tdaff7c0fc0b13275@mail.gmail.com> To: Chris Trahey Cc: Larry Garfield , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] reference caller object From: rquadling@googlemail.com (Richard Quadling) 2009/9/17 Chris Trahey : > It seems worthwhile in a service-provider situation where you do not wish= to > enforce use of $this in service consumers. > The service provider can impliment caller without modifying existing code= . > > Semantically, it should be considered redundant to pass $this in a method > call. There should be an implicit way for a message recipient to determin= e > who is sending the message, in a uniform way (not left up to the consumer= s > of your API to impliment). > > Thanks for your consideration. > > Chris Trahey > Sent from my iPhone > > On Sep 16, 2009, at 8:47 PM, Larry Garfield wrot= e: > >> If the object needs to behave differently based on who called it, there'= s >> already a very easy way to do that: >> >> class A { >> =C2=A0function foo() { >> =C2=A0 $b =3D new B(); >> =C2=A0 $b->bar($this); >> =C2=A0} >> } >> >> class B { >> =C2=A0function bar($caller) { >> =C2=A0 if ($caller instance of A) { >> =C2=A0 =C2=A0 =C2=A0// .. >> =C2=A0 } >> =C2=A0} >> } >> >> That's also therefore much more self-documenting and easier to test >> (because >> you can simulate what gets passed in) than a magic keyword. =C2=A0I don'= t see a >> need for new magic constants here. >> >> On Wednesday 16 September 2009 3:59:16 pm Chris Trahey wrote: >> > (Please direct me elsewhere if necessary, this is a feature request) >> > >> > It would be handy to allow a method to behave differently based on who >> > is >> > calling it. >> > the function I am looking for would essentially do this: >> > >> > function getCaller(){ >> > =C2=A0 =C2=A0 =C2=A0 $bt =3D debug_backtrace(); >> > =C2=A0 =C2=A0 =C2=A0 return $bt[2]['object']; >> > } >> > But of course, there is a lot of uneccessary processing with that call= . >> > Perhaps it could be implimented similar to "self" and "parent" (actual= y >> > more like "static") keywords. >> > >> > So you could do: >> > public function registerMe() { >> > =C2=A0 =C2=A0 =C2=A0 if( ! (caller instanceof 'my_interface')) throw n= ew >> > dev_execption(); >> > =C2=A0 =C2=A0 =C2=A0 if( ! ($this->authenticateMod(caller))) throw new >> > admin_exception('module >> > not active'); >> > =C2=A0 =C2=A0 =C2=A0 $this->loadedMods[caller->module_id()] =3D caller= ; >> > =C2=A0 =C2=A0 =C2=A0 return caller->onLoad(); >> > } >> > >> > Chris Trahey >> > Web Applications Developer >> > Database Administrator >> > CSISD [Technology] >> >> -- >> Larry Garfield >> larry@garfieldtech.com >> >> -- > Isn't this exactly what the backtrace is for? --=20 ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474= 731 ZOPA : http://uk.zopa.com/member/RQuadling