Page 1 of 1

Is it possible to tell where a method was called from?

Posted: Tue Jul 25, 2006 8:14 pm
by Luke
Say I have one class like this... Is it possible to find out from which class (and method if possible) another class is called from?

Code: Select all

class someClass{
    function someClass(){
        $obj = new otherClass();
        $obj->doSomething();
    }
}
class otherClass{
    function doSomething(){
        $this->source = //Some way to find out where this was called from
    }
}
I know I could pass the doSomething method a variable with $this in it... is there any way for the method to know AUTOMATICALLY though?

Posted: Tue Jul 25, 2006 8:20 pm
by feyd
automatically, no. But with debug_backtrace() yes.

Posted: Tue Jul 25, 2006 10:38 pm
by daedalus__
Would magic constants work?

Posted: Tue Jul 25, 2006 10:45 pm
by John Cartwright
no

Posted: Tue Jul 25, 2006 10:46 pm
by feyd
Unless I'm forgetting one, all the magic constants are specific to the lines, files, functions and classes that request them only.