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程序设计有所帮助。

相关文章

php通过function_exists检测函数是否存在的方法

本文实例讲述了php通过function_exists检测函数是否存在的方法。分享给大家供大家参考。具体分析如下: php中可以通过function_exists()函数检测另外一个函数...

php fread函数使用方法总结

php fread函数用于读取文件(可安全用于二进制文件),其语法是fread(file,length),参数file必需,指规定要读取打开文件,length 必需,指规定要读取的最大字...

php生成rss类用法实例

本文实例讲述了php生成rss类用法,分享给大家供大家参考。具体如下: <?php require('rssbuilder.class.php'); header('C...

PHP垃圾回收机制简单说明

虽然自己也是PHP的学习者,但之前还真没怎么了解PHP内部的垃圾回收流程,只是在我们的代码中用了unset,null,mysql_close,__destruct等等一些函数去释放对象防...

php使用NumberFormatter格式化货币的方法

本文实例讲述了php使用NumberFormatter格式化货币的方法。分享给大家供大家参考。具体实现方法如下: $amount = '12345.67'; $formatter =...