使用debug_backtrace调试PHP代码 [英] Debugging PHP Code with debug_backtrace

查看:106
本文介绍了使用debug_backtrace调试PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用别人的代码来节省时间.而且我想开始有效地调试我的脚本以及从其他开发人员继承的脚本.

I love to save time using someone else's code. And I want to start effectively debugging my scripts, as well as scripts I inherit from other developers.

我一直在阅读debug_backtrace(),但不确定是否是我要找的东西.

I've been reading up on debug_backtrace(), and I'm not sure if it's what I'm looking for.

基本上,当实例化一个类时,我想知道正在触发什么方法. 说实话,我想尽可能多地了解,但是知道单个课程中发生的事情真是太棒了.

Basically,when a class is instantiated I want to know what methods are being fired. Truthfully, I'd like to know as much as possible, but knowing what's going on inside a single class would be fantastic.

<?php
require('aHugeComplicatedClass.php'); // sooooo many methods

try {

   $obj = new aHugeComplicatedClass($params);

}
catch(Exception $ex){

   var_dump($ex);

}

?>

从PHP关于 debug_backtrace 的文档中,需要将debug_backtrace()函数放置在任何和所有类的每个方法/函数中,以了解如何实现.

From PHP's docs about debug_backtrace, it looks like I need to place the debug_backtrace() function inside each method/function within any and all classes, just to see how it was reached.

我得读这个太字面的东西.那将是大量的修改.

I gotta be reading this too literal. That would be a ton of modifications.

因此,如果我有一个php文件,它实例化了一个类,并且我知道该类是从其他类扩展的,那么调试该Object的最简单方法是什么?

So, if I have a php file, that instantiates a class, and I know this class is extended from other classes, what's the simpliest way to debug that Object?

推荐答案

我将安装XDebug并将远程调试连接到您的IDE(例如PhpStorm或Eclipse),这样一来,您将获得有关所有错误的不错的堆栈转储,以及可以随意断点代码并随意检查堆栈和所有对象内部.

I would install XDebug and hook up the remote debugging to your IDE (e.g PhpStorm or Eclipse), that way you will get nice stack dumps on all errors, plus the ability to breakpoint your code and inspect the stack and all object internals at your leisure.

http://xdebug.org/

您还可以使用它来配置应用程序调用链,而无需进行任何代码更改(听起来更像是您想要的).通过使用生成大量日志文件的分析选项,您可以将这些日志加载到webgrind中,并直观地检查谁在用好的树形结构调用什么.

You can also use it to profile your application call chains without making any code changes (which sounds more like what you are wanting). By using the profiling options, which generate big log files, you can then load these logs into webgrind and visually inspect who's calling what in nice tree structures.

https://code.google.com/p/webgrind/

Zend工具链还提供了开箱即用的这种更深层的调试功能.

The Zend tool chain would also provide this kind of deeper debugging functionality out of the box.

或者,为类似的代码配置,安装诸如Application Dynamics或New Relic之类的Application Performance Monitoring代理.对于远程安装(即生产)来说,这是最有用的,在这种情况下,调试是不可行的,而分析则很昂贵.

Alternatively install an Application Performance Monitoring agent such as App Dynamics or New Relic for similar code-profiling. This is most useful for remote installations (i.e. production) where debugging isn't an option and profiling is expensive.

这篇关于使用debug_backtrace调试PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆