php的内置函数debug_backtrace()与get_included_files()跟踪代码调用(Thinkphp框架举例)
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框架举例)的更多相关文章
- python_way,day4 内置函数(callable,chr,随机验证码,ord),装饰器
python_way,day4 1.内置函数 - 下 制作一个随机验证码 2.装饰器 1.内置函数 - 下 callable() #对象能否被调用 chr() #10进制数字对应的ascii码表中的内 ...
- Day4 内置函数补充、装饰器
li = [11,22,33,44]def f1(arg): arg.append(55)#函数默认返回值None,函数参数传递的是引用li = f1(li) print(li) 内置函数补充: ...
- Python常用模块中常用内置函数的具体介绍
Python作为计算机语言中常用的语言,它具有十分强大的功能,但是你知道Python常用模块I的内置模块中常用内置函数都包括哪些具体的函数吗?以下的文章就是对Python常用模块I的内置模块的常用内置 ...
- python学习交流 - 内置函数使用方法和应用举例
内置函数 python提供了68个内置函数,在使用过程中用户不再需要定义函数来实现内置函数支持的功能.更重要的是内置函数的算法是经过python作者优化的,并且部分是使用c语言实现,通常来说使用内置函 ...
- day15,内置函数一
1,复习,如何从生成器里面取值,next(每次取一个值),send(不可以用在第一个,取下一个的时候,给上一个地方传一个值),for(没有break会一直取,直到取完),强制转换(会一次性把数据加载到 ...
- python第十二天 生成器,迭代器,内置函数
第二模块学习: 生成器,迭代器,内置函数 生成器特点:只有在调用时才会生成相应的数据,运行的速度快! 示例: def fil(max):#斐波那契数 n,a,b=0,0,1 #定义初始数据 whil ...
- gcc 内置函数
关于gcc内置函数和c隐式函数声明的认识以及一些推测 最近在看APUE,不愧是经典,看一点就收获一点.但是感觉有些东西还是没说清楚,需要自己动手验证一下,结果发现需要用gcc,就了解一下. 有时候 ...
- 关于gcc内置函数和c隐式函数声明的认识以及一些推测
最近在看APUE,不愧是经典,看一点就收获一点.但是感觉有些东西还是没说清楚,需要自己动手验证一下,结果发现需要用gcc,就了解一下. 有时候,你在代码里面引用了一个函数但是没有包含相关的头文件,这个 ...
- Python学习之==>内置函数、列表生成式、三元表达式
一.内置函数 所谓内置函数就是Python自带的函数 print(all([0,2,3,4])) #判断可迭代的对象里面的值是否都为真 print(any([0,1,2,3,4])) #判断可迭代的对 ...
随机推荐
- Spring怎么引入多个xml配置文件
方式一:在web.xml中通过<context-param> 标签引入 <context-param> <param-name>contextConfigLocat ...
- 译-BSA NSH Command介绍
BSA NSH Command全称BMC BladeLogic Network Shell Command,是基于ZSH的shell. 1 说明 NSH命令行(全称Network Shell,又称为 ...
- java 表现层:jsp、freemarker、velocity
在java领域,表现层技术主要有三种:jsp.freemarker.velocity. jsp是大家最熟悉的技术 优点: 1.功能强大,可以写java代码 2.支持jsp标签(jsp tag) 3.支 ...
- Linux中的shell到底是什么
(引自:https://zhidao.baidu.com/question/557066905.html) [一] shell的含义: 首先shell的英文含义是"壳": 它是相对 ...
- wer
概述 快速入门流程: 使用叮当扫码产品请遵循以下操作步骤: 1. 新建项目信息 2. 新建产品信息 3. 添加发货产品 4. 发货 5. 收货 (具体使用操作请查看详细的使用说明) 文档目的: 本文档 ...
- 零基础实现node+express个性化聊天室
本篇文章使用node+express+jquery写一个个性化聊天室,一起来get一下~(源码地址见文章末尾) 效果图 项目结构 实现功能 登录检测 系统自动提示用户状态(进入/离开) 显示在线用户 ...
- Akamai CDN
Akamai CDN中的几个重要组件 mapping system 调度系统(映射client到edge cluster,进而到edge server) edge server platform 边缘 ...
- SpringBoot与Mybatis整合方式01(源码分析)
前言:入职新公司,SpringBoot和Mybatis都被封装了一次,光用而不知道原理实在受不了,于是开始恶补源码,由于刚开始比较浅,存属娱乐,大神勿喷. 就如网上的流传的SpringBoot与Myb ...
- Java I/O基础
字节流和字符流的区别,字节流一次读取一个字节,字符流一次读取的是一个Unicode码,读取了2个字节. 可以以文本编辑器打开的可以使用字符流读取,否则用字符流读取可能就会出错.图像文件就需要用字节流读 ...
- 创建一个vue项目的过程
创建一个vue项目: 1.首先从UI手上拿到PSD设计图,然后看设计搞的内容,需要做个大概的页面布局 2.做vue之前不许安装node,因为做vue项目要和node结合使用 3.然后安装vue脚手架: ...