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])) #判断可迭代的对 ...
随机推荐
- 浅析final关键字
浅析final关键字 final单词字面意思是"最终的,不可更改的".所以在java中final关键字表示终态,即最终的状态,"这个东西不能被改变". fina ...
- python_如何对实例属性进行类型检查?
案例: 在某项目中,我们实现了一些类,并希望能像静态语言那样对他们的实例属性进行类型检查 p = Person() p.name = 'xi_xi' # 必须是str p.age = ...
- SSM与jsp传递实体类
jsp传controller Controller: @RequestMapping({"/user"}) public void registerUser(User uu) th ...
- eclipse:Workspace in use or cannot be created
打开eclipse出现:Workspace in use or cannot be created, choose a different one 原因:出现这种情况一般是workspace的配置文件 ...
- java1.8--Optional类
身为一名Java程序员,大家可能都有这样的经历:调用一个方法得到了返回值却不能直接将返回值作为参数去调用别的方法.我们首先要判断这个返回值是否为null,只有在非空的前提下才能将其作为其他方法的参数. ...
- 一个HTTP Basic Authentication引发的异常
这几天在做一个功能,其实很简单.就是调用几个外部的API,返回数据后进行组装然后成为新的接口.其中一个API是一个很奇葩的API,虽然是基于HTTP的,但既没有基于SOAP规范,也不是Restful风 ...
- git 不成功
fatal: Interactive git shell is not enabled.hint: ~/git-shell-commands should exist and have read an ...
- python --- mulitprocessing(多进程)模块使用
1. 什么是进程? 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在早期面向进程设计的计算机结构中,进程是程序的基本执 ...
- ado.net 参数传递之 in
之前项目有一放行的功能,对某界面维护时(数据的增删改),先将数据保存到临时表中,放行后再真正的写入到库中.由于设计到主从表多中约束关系,所以当时我采用的是写一个存储过程来对某个界面的操作进行统一处理, ...
- Hyperledger Fabric Chaincode for Operators——实操智能合约
什么是Chaincode(智能合约)? chaincode是一个程序,它是使用Go语言编写的,最终在Java等其他编程语言中实现了指定的接口.chaincode运行在一个被背书peer进程独立出来的安 ...