php的内置函数debug_backtrace()与get_included_files()跟踪代码调用(Thinkphp框架举例)详解编程语言
2023-06-13 09:11:47 时间
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; print_r(debug_backtrace());die; //函数位置
[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 [1] = Array [file] = D:/phpStudy/WWW/wwwroot/Runtime/common~runtime.php [line] = 1 [function] = invoke [class] = ReflectionMethod [object] = ReflectionMethod Object [name] = index [class] = Home/Controller/IndexController [type] = - [args] = Array [0] = Home/Controller/IndexController Object [view:protected] = Think/View Object [tVar:protected] = Array [theme:protected] = [config:protected] = Array [2] = Array [file] = D:/phpStudy/WWW/wwwroot/Runtime/common~runtime.php [line] = 1 [function] = exec [class] = Think/App [type] = :: [args] = Array [3] = Array [file] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Think.class.php [line] = 117 //117行 [function] = run //Think.class.php文件的run方法 [class] = Think/App [type] = :: [args] = Array [4] = Array [file] = D:/phpStudy/WWW/wwwroot/ThinkPHP/ThinkPHP.php [line] = 94 //ThinkPHP文件的94行 [function] = start //经过了start函数 [class] = Think/Think [type] = :: [args] = Array [5] = Array [file] = D:/phpStudy/WWW/wwwroot/index.php [line] = 39 //第39行 [args] = Array [0] = 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; print_r(get_included_files());die;
[0] = D:/phpStudy/WWW/wwwroot/index.php [1] = D:/phpStudy/WWW/wwwroot/ThinkPHP/ThinkPHP.php [2] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Think.class.php [3] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Storage.class.php [4] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Storage/Driver/File.class.php [5] = D:/phpStudy/WWW/wwwroot/Runtime/common~runtime.php [6] = D:/phpStudy/WWW/wwwroot/Application/Common/Behavior/InitHookBehavior.class.php [7] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Behavior.class.php [8] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Cache.class.php [9] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Cache/Driver/File.class.php [10] = D:/phpStudy/WWW/wwwroot/Application/Home/Conf/config.php [11] = D:/phpStudy/WWW/wwwroot/Application/Home/Common/function.php [12] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php [13] = D:/phpStudy/WWW/wwwroot/Application/Home/Controller/IndexController.class.php [14] = D:/phpStudy/WWW/wwwroot/Application/Home/Controller/HomeController.class.php [15] = D:/phpStudy/WWW/wwwroot/Application/Common/Api/ConfigApi.class.php [16] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Model.class.php [17] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Db.class.php [18] = D:/phpStudy/WWW/wwwroot/ThinkPHP/Library/Think/Db/Driver/Mysqli.class.php )
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/17124.html
cjavamysqlphp
相关文章
- PHP常见面试题_php面试常问面试题
- 【说站】PHP有哪些屏蔽错误的方法
- 2022 IDE各种激活的,码上用起来吧 ,java、python、php、go等等
- PHP 拼手气红包分配算法
- 分享一个简单的PHP分页类源码
- 【笔记php】如何使用PHP从JSON提取数据?
- 解决:无法将“php”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- PHP异步MySQL:提升网站性能的新方案(php异步mysql)
- 借助 PHP 与 MySQL 轻松实现文件下载(php和mysql下载)
- 从PHP与MySQL结合 创造美好图片(php图片mysql)
- 命令在PHP中执行Linux命令的方法(php执行linux)
- php在Linux上使用Yaf框架开发PHP应用(yaflinux)
- MySQL验证:PHP实现细节(php验证mysql)
- PHP实现MSSQL数据库高效操作(php操作mssql)
- PHP后门新玩法:一款猥琐的PHP后门分析
- Redis现在支持PHP啦!(redis支持php)
- 基于PHP和MSSQL 的网站用户注册系统(php mssql 注册)
- PHP MSSQL框架:为企业开发更好的应用程序(php mssql 框架)
- Linux下实现高效的PHP配置(linux下php配置)
- 检查PHP Redis环境实现快速可靠性服务(检查php redis)
- PHP框架下的Redis应用实现(用php redis)
- 强悍的表现PHP与Redis的连接(redis链接php)
- 强烈推荐:php.ini中文版(1)
- 需要使用php模板的朋友必看的很多个顶级PHP模板引擎比较分析
- php连接mysql数据库代码
- PHP输出控制功能在简繁体转换中的应用
- 让的PHP代码飞起来的40条小技巧(提升php效率)
- PHP隐形一句话后门,和ThinkPHP框架加密码程序(base64_decode)
- win7+apache+php+mysql环境配置操作详解
- PHP防止注入攻击实例分析
- PHP中使用TCPDF生成PDF文档实例
- php使用sqlserver验证连接数据库的方法
- 图解找出PHP配置文件php.ini的路径的方法