本文實例講述了PHP堆棧調試操作。分享給大家供大家參考,具體如下:
你是否想知道當前函數被哪些文件調用了,如果知道了這些路徑,我們就能很好的理解程序的執行過程,這是非常重要的,也是了解別人程序的基礎,那么這里我就給大家介紹一種php中的堆棧調試的方法,其實就是php內置的一個函數debug_backtrace()
;
下面是就稍微介紹一下吧,具體還是要看手冊哦,喜歡看手冊的程序員才是前途無量的
$statcks = debug_backtrace(); $tmp_arr = array(); if(!$stacks) return $tmp_arr; foreach($stacks as $k=>$v) { $tmp[$k]['file'] = isset($v['file']) ? $v['file'] : '--'; $tmp[$k]['line'] = isset($v['line'])? $v['line'] : '--'; $tmp[$k]['function'] = isset($v['function']) ? $v['function'] : '--'; }
運行結果:
Array
(
[0] => Array
(
[file] => D:\wwwroot\CodeIgniter\application\controllers\finance\channel.php
[line] => 128
[function] => get_total_rows
)
[1] => Array
(
[file] => --
[line] => --
[function] => index
)
[2] => Array
(
[file] => D:\wwwroot\CodeIgniter\application\controllers\finance\channel.php
[line] => 46
[function] => call_user_func
)
[3] => Array
(
[file] => --
[line] => --
[function] => get_nav
)
[4] => Array
(
[file] => D:\wwwroot\CodeIgniter\system\core\CodeIgniter.php
[line] => 360
[function] => call_user_func_array
)
[5] => Array
(
[file] => D:\wwwroot\CodeIgniter\index.php
[line] => 205
[function] => require_once
)
)
這里是打印出來的數組,非常的好了
希望本文所述對大家PHP程序設計有所幫助。