PHP堆栈调试操作简单示例

yipeiwu_com7年前PHP代码库

本文实例讲述了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相关内容感兴趣的读者可查看本站专题:《PHP错误与异常处理方法总结》、《php字符串(string)用法总结》、《PHP数组(Array)操作技巧大全》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

相关文章

Zend Guard使用指南及问题处理

Zend Guard是目前市面上最成熟的PHP源码加密产品了。 刚好需要对自己的产品进行加密,折腾了一晚上,终于搞定,将碰到的问题及解决方法记录下来,方便日后需要,也可以帮助其他人。 我...

『PHP』PHP截断函数mb_substr()使用介绍

Function: mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处 $length,长度...

隐性调用php程序的方法

调用方法:<script language = "javascript" src = "count.php"></script> count.php源码:复制代码...

thinkphp中连接oracle时封装方法无法用的解决办法

thinkphp中连接oracle时封装方法无法用的解决办法

最近收集了一些关于THinkPHP连接Oracle数据库的问题,有很多朋友按照连接mysql的方法来操作,导致有一些方法在Oreale中无法正常使用。比如说:findAll,Select...

PHP Directory 函数的详解

预定义常量: DIRECTORY_SEPARATOR (string) :目录分隔符 PATH_SEPARATOR (string) :路径分隔符 bool chdir ( string...