If we want to know who called a method? Debug_print_backtrace
Debug_print_backtrace () can print out the call process of a page, from where to see clearly.
However, this is a PHP5 proprietary function. Fortunately, it has been implemented in pear,
Http://pear.php.net/package/PHP_Compat
Test codeCopy codeThe Code is as follows: <? Php
Class {
Function say ($ msg ){
Echo "msg:". $ msg;
Echo "<pre>"; debug_print_backtrace ();
}
}
Class B {
Function say ($ msg ){
$ A = new ();
$ A-> say ($ msg );
}
}
Class c {
Function _ construct ($ msg ){
$ B = new B ();
$ B-> say ($ msg );
}
}
$ C = new c ("test ");
Output resultCopy codeThe Code is as follows: msg: test
#0 a-> say (test) called at [/var/www/test/test0723.php: 12]
#1 B-> say (test) called at [/var/www/test/test0723.php: 19]
#2 c->__ construct (test) called at [/var/www/test/test0723.php: 23]
Related Links
Http://ch2.php.net/manual/zh/function.debug-print-backtrace.php
Http://ch2.php.net/manual/zh/function.debug-backtrace.php