你是否想知道當前函數被哪些文件調用了,如果知道了這些路徑,我們就能很好的理解程序的執行過程,這是非常重要的,也是了解別人程序的基礎,那麼這裡我就給大家介紹一種php中的堆疊調試的方法,其實就是php內建的一個函數debug_backtrace();
下面是就稍微介紹一下吧,具體還是要看手冊哦,喜歡看手冊的程式設計師才是前途無量的
<code>$statcks = debug_backtrace(); $tmp_arr = array(); <span>if</span>(!$stacks) <span>return</span> $tmp_arr; foreach($stacks as $k=>$v) { $tmp[$k][<span>'file'</span>] = isset($v[<span>'file'</span>]) ? $v[<span>'file'</span>] : <span>'--'</span>; $tmp[$k][<span>'line'</span>] = isset($v[<span>'line'</span>])? $v[<span>'line'</span>] : <span>'--'</span>; $tmp[$k][<span>'function'</span>] = isset($v[<span>'function'</span>]) ? $v[<span>'function'</span>] : <span>'--'</span>; } Array ( [<span>0</span>]<span> =></span> Array ( [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\application\controllers\finance\channel.php [line]<span> =></span><span>128</span> [<span>function</span>]<span> =></span> get_total_rows ) [<span>1</span>]<span> =></span> Array ( [file]<span> =></span> -- [line]<span> =></span> -- [<span>function</span>]<span> =></span> index ) [<span>2</span>]<span> =></span> Array ( [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\application\controllers\finance\channel.php [line]<span> =></span><span>46</span> [<span>function</span>]<span> =></span> call_user_func ) [<span>3</span>]<span> =></span> Array ( [file]<span> =></span> -- [line]<span> =></span> -- [<span>function</span>]<span> =></span> get_nav ) [<span>4</span>]<span> =></span> Array ( [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\system\core\CodeIgniter.php [line]<span> =></span><span>360</span> [<span>function</span>]<span> =></span> call_user_func_array ) [<span>5</span>]<span> =></span> Array ( [file]<span> =></span><span>D</span>:\wwwroot\CodeIgniter\index.php [line]<span> =></span><span>205</span> [<span>function</span>]<span> =></span> require_once ) )</code>
這裡是打印出來的數組,非常的好了
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
以上就介紹了php中堆疊調試,包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。