如何调试PHP脚本?

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

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


当前回答

PhpEd真的很好。你可以进入/进入/退出函数。你可以运行特别代码,检查变量,改变变量。太神奇了。

其他回答

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

display_errors = Off
error_reporting = E_ALL 
display_errors = On

也用过

error_log();
console_log();

我使用了Zend Studio(5.5)和Zend平台。这就提供了适当的调试、断点/跨代码等,尽管是有代价的。

根据问题的不同,我喜欢将error_reporting(E_ALL)与echo测试混合使用(以找到最初发生错误的违规行/文件;你知道它并不总是行/文件php告诉你对吗?),IDE大括号匹配(解决“解析错误:语法错误,意外的$end”问题),和print_r();退出;转储(真正的程序员查看源代码;p)。

你也不能用“memory_get_usage();”和“memory_get_peak_usage();”来打败phpdebug(检查sourceforge)来找到问题区域。

For the really gritty problems that would be too time consuming to use print_r/echo to figure out I use my IDE's (PhpEd) debugging feature. Unlike other IDEs I've used, PhpEd requires pretty much no setup. the only reason I don't use it for any problems I encounter is that it's painfully slow. I'm not sure that slowness is specific to PhpEd or any php debugger. PhpEd is not free but I believe it uses one of the open-source debuggers (like XDebug previously mentioned) anyway. The benefit with PhpEd, again, is that it requires no setup which I have found really pretty tedious in the past.

XDebug对于开发至关重要。我安装它之前任何其他扩展。它为您提供任何错误的堆栈跟踪,您可以轻松地启用分析。

使用var_dump()可以快速查看数据结构。不要使用print_r(),因为你必须用<pre>包围它,而且它一次只打印一个var。

<?php var_dump(__FILE__, __LINE__, $_REQUEST); ?>

对于一个真正的调试环境,我发现最好的是Komodo IDE,但它要花费$$。