debug_print_backtrace() 是一個很低調的函數,很少有人注意過它. 不過當我對着一個對象調用另一個對象再調用其它的對象和文件中的一個函數出錯時,它也許正在一邊笑呢
如果我們想知道某個方法被誰調用了? debug_print_backtrace可以解決
debug_print_backtrace() 可以打印出一個頁面的調用過程 , 從哪兒來到哪兒去一目了然.
不過這是一個PHP5的專有函數,好在pear中已經有了實現,
案例1
<?php class a{ function say($msg) { echo "msg:".$msg; echo "<pre>";debug_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");
案例2
<?php function one($str1, $str2) { two("Glenn", "Quagmire"); } function two($str1, $str2) { three("Cleveland", "Brown"); } function three($str1, $str2) { echo '<pre>'; debug_backtrace(); } echo one('a','b'); ?>