debug_backtrace()

在我们开发一个项目中,或者二开研究某个开源程序,需要对代码流程一步步去跟踪,来研究它的逻辑,才可以进行修改,达到我们的开发目的。php的内置函数debug_backtrace就具备这个功能,很直观的展示出从系统流程开始到执行终止的位置之前所走过的所有文件,函数,甚至调用的参数,还会具体到某个行数。

这里是官方的说明

http://php.net/manual/zh/function.debug-backtrace.php

下面我来用Thinkphp框架来举例,说明从进入index控制器下的index方法过程中,是怎么走过来的。

<?php

namespace Home\Controller;
use OT\DataDictionary; //index 控制器
class IndexController extends HomeController { //index方法
public function index(){
echo '<pre>';
print_r(debug_backtrace());die; //函数位置 $this->display();
} }

然后执行PHP程序,看结果(从下往上看,才是执行流程)

Array
(
[] => Array
(
[function] => index
[class] => Home\Controller\IndexController
[object] => Home\Controller\IndexController Object
(
[view:protected] => Think\View Object
(
[tVar:protected] => Array
(
) [theme:protected] =>
) [config:protected] => Array
(
) ) [type] => ->
[args] => Array
(
) ) [] => Array
(
[file] => D:\phpStudy\WWW\wwwroot\Runtime\common~runtime.php
[line] =>
[function] => invoke
[class] => ReflectionMethod
[object] => ReflectionMethod Object
(
[name] => index
[class] => Home\Controller\IndexController
) [type] => ->
[args] => Array
(
[] => Home\Controller\IndexController Object
(
[view:protected] => Think\View Object
(
[tVar:protected] => Array
(
) [theme:protected] =>
) [config:protected] => Array
(
) ) ) ) [] => Array
(
[file] => D:\phpStudy\WWW\wwwroot\Runtime\common~runtime.php
[line] =>
[function] => exec
[class] => Think\App
[type] => ::
[args] => Array
(
) ) [] => Array
(
[file] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Think.class.php
[line] => //117行
[function] => run //Think.class.php文件的run方法
[class] => Think\App
[type] => ::
[args] => Array
(
) ) [] => Array
(
[file] => D:\phpStudy\WWW\wwwroot\ThinkPHP\ThinkPHP.php
[line] => //ThinkPHP文件的94行
[function] => start //经过了start函数
[class] => Think\Think
[type] => ::
[args] => Array
(
) ) [] => Array
(
[file] => D:\phpStudy\WWW\wwwroot\index.php
[line] => //第39行
[args] => Array
(
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\ThinkPHP.php
) [function] => require
) )

说明一下ThinkPHP框架的执行流程:

Index.php加载了Thinkphp.php文件 ---->  ThinkPHP.php执行Think.start() ----> Think.class.php中执行App::run() ----> App.class.php中执行 App::exec() ----->App::exec()中用反射方法调用了控制器

get_included_files()

此函数是打印在项目流程执行过程中被引入的文件

<?php

namespace Home\Controller;
use OT\DataDictionary; //index 控制器
class IndexController extends HomeController { //index方法
public function index(){
echo '<pre>';
print_r(get_included_files());die; $this->display();
} }

打印结果

Array
(
[] => D:\phpStudy\WWW\wwwroot\index.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\ThinkPHP.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Think.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Storage.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Storage\Driver\File.class.php
[] => D:\phpStudy\WWW\wwwroot\Runtime\common~runtime.php
[] => D:\phpStudy\WWW\wwwroot\Application\Common\Behavior\InitHookBehavior.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Behavior.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Cache.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Cache\Driver\File.class.php
[] => D:\phpStudy\WWW\wwwroot\Application\Home\Conf\config.php
[] => D:\phpStudy\WWW\wwwroot\Application\Home\Common\function.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Behavior\ReadHtmlCacheBehavior.class.php
[] => D:\phpStudy\WWW\wwwroot\Application\Home\Controller\IndexController.class.php
[] => D:\phpStudy\WWW\wwwroot\Application\Home\Controller\HomeController.class.php
[] => D:\phpStudy\WWW\wwwroot\Application\Common\Api\ConfigApi.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Model.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Db.class.php
[] => D:\phpStudy\WWW\wwwroot\ThinkPHP\Library\Think\Db\Driver\Mysqli.class.php
)

php的内置函数debug_backtrace()与get_included_files()跟踪代码调用(Thinkphp框架举例)的更多相关文章

  1. python_way,day4 内置函数(callable,chr,随机验证码,ord),装饰器

    python_way,day4 1.内置函数 - 下 制作一个随机验证码 2.装饰器 1.内置函数 - 下 callable() #对象能否被调用 chr() #10进制数字对应的ascii码表中的内 ...

  2. Day4 内置函数补充、装饰器

    li = [11,22,33,44]def f1(arg): arg.append(55)#函数默认返回值None,函数参数传递的是引用li = f1(li) print(li)   内置函数补充: ...

  3. Python常用模块中常用内置函数的具体介绍

    Python作为计算机语言中常用的语言,它具有十分强大的功能,但是你知道Python常用模块I的内置模块中常用内置函数都包括哪些具体的函数吗?以下的文章就是对Python常用模块I的内置模块的常用内置 ...

  4. python学习交流 - 内置函数使用方法和应用举例

    内置函数 python提供了68个内置函数,在使用过程中用户不再需要定义函数来实现内置函数支持的功能.更重要的是内置函数的算法是经过python作者优化的,并且部分是使用c语言实现,通常来说使用内置函 ...

  5. day15,内置函数一

    1,复习,如何从生成器里面取值,next(每次取一个值),send(不可以用在第一个,取下一个的时候,给上一个地方传一个值),for(没有break会一直取,直到取完),强制转换(会一次性把数据加载到 ...

  6. python第十二天 生成器,迭代器,内置函数

    第二模块学习:  生成器,迭代器,内置函数 生成器特点:只有在调用时才会生成相应的数据,运行的速度快! 示例: def fil(max):#斐波那契数 n,a,b=0,0,1 #定义初始数据 whil ...

  7. gcc 内置函数

    关于gcc内置函数和c隐式函数声明的认识以及一些推测   最近在看APUE,不愧是经典,看一点就收获一点.但是感觉有些东西还是没说清楚,需要自己动手验证一下,结果发现需要用gcc,就了解一下. 有时候 ...

  8. 关于gcc内置函数和c隐式函数声明的认识以及一些推测

    最近在看APUE,不愧是经典,看一点就收获一点.但是感觉有些东西还是没说清楚,需要自己动手验证一下,结果发现需要用gcc,就了解一下. 有时候,你在代码里面引用了一个函数但是没有包含相关的头文件,这个 ...

  9. Python学习之==>内置函数、列表生成式、三元表达式

    一.内置函数 所谓内置函数就是Python自带的函数 print(all([0,2,3,4])) #判断可迭代的对象里面的值是否都为真 print(any([0,1,2,3,4])) #判断可迭代的对 ...

随机推荐

  1. PL/SQL FAQ in installation "make sure you have the 32 bits Oracle client installed" and "Database character set(AL32UTF8) and Client character set (GBK) are different"

    requirement : connecting to remote oracle server . now I know  the connectionURL :connectionUrl :jdb ...

  2. JDOJ-P1260 VIJOS-P1083 小白逛公园

    首先,在这里给大家推荐一个网站,https://neooj.com:8082,这是我母校的网站 言归正传,题目描述 VIJOS-P1083 小白逛公园 Time Limit: 1 Sec  Memor ...

  3. pandas 处理dataframe(一)

    1.读取csv文件 df = pd.read_csv('30lines.csv') 2.删除第一列 df.drop(df.columns[[0]].axis=1,inplace=True) 3. co ...

  4. Not Found The requested URL / was not found on this server.

    http://www.wanysys.cc/coding/php/800.html 今天在做本地PHP项目的时候,想把之前wampserver的本地虚拟服务器环境访问方式改为本地localhost访问 ...

  5. 记React+.NetCore API实现动态列导出

    1.效果演示 2.用到的第三方类库 前端:React,Dva,Antd 后端:ASP.NET CORE,System.Linq.Dynamic.Core,EPPlus.Core 3.基本思路 第一:E ...

  6. JAVA中默认的编码方式

    转:http://blog.csdn.net/scyatcs/article/details/31356823 编码问题存在两个方面:JVM之内和JVM之外.1.Java文件编译后形成class这里J ...

  7. Optaplanner - 入门介绍

    OptaPlanner背景 在上一篇里喷了不少水,这一篇准备放点干货:其实也没办法完全干,因为很多预备知道在交待一下.好了,说一下关于OptaPlanner的背景.应用兼容性及其原理. 这一篇先说一下 ...

  8. JS对象、原型链

    忘记在哪里看到过,有人说鉴别一个人是否 js 入门的标准就是看他有没有理解 js 原型,所以第一篇总结就从这里出发. 对象 JavaScript 是一种基于对象的编程语言,但它与一般面向对象的编程语言 ...

  9. 不需要客户端插件PHP也能实现单点登录

    分析CAS原理,构建PHP单点登录 单点登录(Single Sign On , 简称 SSO )是目前比较流行的服务于企业业务整合的解决方案之一, SSO 使得在多个应用系统中,用户 只需要登录一次就 ...

  10. HTML图片上下之间的空隙是什么原因

    在这个问题上,<权威指南>该书第三版第 146 页有明确说到: 如果一个垂直元素没有基线——也就是说,这是一个图像或表单输入元素,或者其它替换元素——那么该元素低端与其父元素的基线对齐.这 ...