October 28, 2010
Find who calls a method in PHP's class
Question by balkon_smoke
Possible Duplicate:
Find out which class called a method in another class.
Hello everyone,
I have a class and I can’t find where his object creates.
I mean, can I somehow find out who calls his constructor?
Thanks a lot,
Andrey.
Answer by Starx
use
$trace = debug_backtrace();
echo "<pre>".print_r($trace[1])."</pre>";
//see all the displays '1' is the referrer '0' is self
echo $callingfunction = $trace[1]['function'];
echo $callingclass = $trace[1]['class'];