您的位置:首页 > 编程语言 > PHP开发

php中堆栈调试

2015-07-27 22:57 816 查看
你是否想知道当前函数被哪些文件调用了,如果知道了这些路径,我们就能很好的理解程序的执行过程,这是非常重要的,也是了解别人程序的基础,那么这里我就给大家介绍一种php中的堆栈调试的方法,其实就是php内置的一个函数
debug_backtrace();


下面是就稍微介绍一下吧,具体还是要看手册哦,喜欢看手册的程序员才是前途无量的

[code]$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
        )

)


这里是打印出来的数组,非常的好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: