如何调试PHP脚本?

我知道基本的调试,如使用错误报告。PHPEclipse中的断点调试也非常有用。

在phpStorm或任何其他IDE中调试的最佳方法(就快速和简单而言)是什么?


当前回答

有许多PHP调试技术可以在编码时节省无数的时间。一个有效但基本的调试技术是简单地打开错误报告。另一种稍微高级一点的技术涉及到使用print语句,它可以通过在屏幕上显示实际发生的内容来帮助查明更难以捉摸的错误。PHPeclipse是一个Eclipse插件,可以突出显示常见的语法错误,并且可以与调试器一起使用来设置断点。

display_errors = Off
error_reporting = E_ALL 
display_errors = On

也用过

error_log();
console_log();

其他回答

PhpEdit有一个内置调试器,但我通常最终使用echo();和print_r ();老式的方式!!

我使用Netbeans的XDebug和Easy XDebug FireFox插件

The add-on is essential when you debug MVC projects, because the normal way XDebug runs in Netbeans is to register the dbug session via the url. With the add-on installed in FireFox, you would set your Netbeans project properties -> Run Configuratuion -> Advanced and select "Do Not Open Web Browser" You can now set your break points and start the debugging session with Ctrl-F5 as usual. Open FireFox and right-click the Add-on icon in the right bottom corner to start monitoring for breakpoints. When the code reaches the breakpoint it will stop and you can inspect your variable states and call-stack.

坦率地说,是print和print_r()的组合,以打印出变量。我知道很多人更喜欢使用其他更高级的方法,但我发现这是最容易使用的。

我要说的是,直到我在Uni做了一些微处理器编程,甚至都不会使用它,我才完全理解这一点。

通常我发现创建一个自定义日志功能可以保存在文件中,存储调试信息,并最终在公共页脚上重新打印。

您还可以重写常见的Exception类,以便这种类型的调试是半自动化的。

Nusphere也是一个很好的php调试器 nusphere