如果我们想知道某个方法被谁调用了?  debug_print_backtrace可以解决!~

测试代码

 1 <?php
 2 class a{
 3     function say($msg) {
 4         echo "msg:".$msg;
 5         echo "<pre>";debug_print_backtrace();
 6     }
 7 }
 8 
 9 class b {
10     function say($msg) {
11         $a = new a();
12         $a->say($msg);
13     }
14 }
15 
16 class c {
17     function __construct($msg) {
18         $b = new b();
19         $b->say($msg);
20     }
21 }
22 
23 $c = new c("test");

输出结果

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]

相关链接

http://ch2.php.net/manual/zh/function.debug-print-backtrace.php

http://ch2.php.net/manual/zh/function.debug-backtrace.php

相关文章:

  • 2021-04-18
  • 2021-05-10
  • 2021-06-21
  • 2021-09-01
  • 2021-11-11
  • 2021-07-19
  • 2021-06-21
猜你喜欢
  • 2021-10-16
  • 2021-12-16
  • 2021-09-11
  • 2021-08-06
  • 2021-05-11
  • 2021-08-12
相关资源
相似解决方案