Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45582 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19579 invoked from network); 17 Sep 2009 03:00:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2009 03:00:48 -0000 Authentication-Results: pb1.pair.com header.from=ctrahey@csisd.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ctrahey@csisd.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain csisd.org from 204.56.144.240 cause and error) X-PHP-List-Original-Sender: ctrahey@csisd.org X-Host-Fingerprint: 204.56.144.240 gateway.csisd.org Received: from [204.56.144.240] ([204.56.144.240:59414] helo=gateway.csisd.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4A/83-29403-E56A1BA4 for ; Wed, 16 Sep 2009 23:00:47 -0400 Received: from gateway.csisd.org (localhost.localdomain [127.0.0.1]) by localhost (Email Security Appliance) with SMTP id 834AE794350_AB1A65CB; Thu, 17 Sep 2009 03:00:44 +0000 (GMT) Received: from mail.csisd.org (email4400.csisd.org [204.56.144.241]) by gateway.csisd.org (Sophos Email Appliance) with ESMTP id C546A7942CB_AB1A659F; Thu, 17 Sep 2009 03:00:41 +0000 (GMT) Received: from [10.31.53.78] (166.205.7.12) by mail.csisd.org (FirstClass Mail Server v9.1 build 9.221) with ESMTP (TLSv1/SSLv3 cypher=AES128-SHA bits=128) (Sender: ctrahey@csisd.org) transient id 13250; Wed, 16 Sep 2009 22:01:37 -0500 References: Message-ID: <7F7F9F17-A755-428B-93A6-1E0AFA20DE50@csisd.org> To: Larry Garfield In-Reply-To: Content-Type: multipart/alternative; boundary=Apple-Mail-1--28630483 Content-Transfer-Encoding: 7bit X-Mailer: iPhone Mail (7A400) Mime-Version: 1.0 (iPhone Mail 7A400) Date: Wed, 16 Sep 2009 22:01:13 -0500 Cc: "internals@lists.php.net" Subject: Re: [PHP-DEV] reference caller object From: ctrahey@csisd.org (Chris Trahey) --Apple-Mail-1--28630483 Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit 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 determine who is sending the message, in a uniform way (not left up to the consumers 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 wrote: > If the object needs to behave differently based on who called it, > there's > already a very easy way to do that: > > class A { > function foo() { > $b = new B(); > $b->bar($this); > } > } > > class B { > function bar($caller) { > if ($caller instance of A) { > // .. > } > } > } > > That's also therefore much more self-documenting and easier to test > (because > you can simulate what gets passed in) than a magic keyword. I 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(){ > > $bt = debug_backtrace(); > > 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" (actualy > > more like "static") keywords. > > > > So you could do: > > public function registerMe() { > > if( ! (caller instanceof 'my_interface')) throw new > dev_execption(); > > if( ! ($this->authenticateMod(caller))) throw new > admin_exception('module > > not active'); > > $this->loadedMods[caller->module_id()] = caller; > > return caller->onLoad(); > > } > > > > Chris Trahey > > Web Applications Developer > > Database Administrator > > CSISD [Technology] > > -- > Larry Garfield > larry@garfieldtech.com > > -- --Apple-Mail-1--28630483--