Debug_print_backtrace () is a very low-key function, and few people notice it. But when I call another object on one object and then call the other object and one of the functions in the file goes wrong, it laughs.
What if we want to know who called a method? Debug_print_backtrace can solve
Debug_print_backtrace () can print out the calling process for a page, from where to where to go to a glance.
But this is a PHP5 proprietary function, fortunately in pear, it has been implemented,
Http://pear.php.net/package/PHP_Compat
Test the code with the following code:
<?php class a{function Say ($msg) {echo "msg:" $MSG; echo "<pre>";d ebug_print_backtrace (); }} Class B {function say ($msg) {$a = new A (); $a->say ($msg);}} Class C {function construct ($msg) {$b = new B (); $b->say ($msg); }} $c = new C ("test");
Output results
The 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]