你是否想知道当前函数被哪些文件调用了,如果知道了这些路径,我们就能很好的理解程序的执行过程,这是非常重要的,也是了解别人程序的基础,那么这里我就给大家介绍一种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教程有兴趣的朋友有所帮助。