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
la...@garfieldtech.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to