2013年5月21日 星期二

debug_print_backtrace | PHP

系統在開發,很常使用到 call function , 甚至會有 func call func , 再 call func ....
PHP提供一個很好 trace function caller 的函式 debug_print_backtrace

以下是來自官網的說明範例





<?php
// include.php file

function a() {
    b();
}

function b() {
    c();
}

function c(){
    debug_print_backtrace();
}

a();

?>



<?php
// test.php file
// this is the file you should run

include 'include.php';
?>


結果如下:

#0  c() called at [/tmp/include.php:10]
#1  b() called at [/tmp/include.php:6]
#2  a() called at [/tmp/include.php:17]
#3  include(/tmp/include.php) called at [/tmp/test.php:3]

沒有留言:

張貼留言