如何调试PHP脚本?

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

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


当前回答

在某种程度上,这取决于事情的走向。这是我尝试分离的第一件事,然后在必要时使用echo/print_r()。

注:你们知道你可以把true作为第二个参数传递给print_r(),它会返回输出而不是打印它吗?例如:

echo "<pre>".print_r($var, true)."</pre>";

其他回答

Komodo IDE works well with xdebug, even for the remore debugging. It needs minimum amount of configuration. All you need is a version of php that Komodo can use locally to step through the code on a breakpoint. If you have the script imported into komodo project, then you can set breakpoints with a mouse-click just how you would set it inside eclipse for debugging a java program. Remote debugging is obviously more tricky to get it to work correctly ( you might have to map the remote url with a php script in your workspace ) than a local debugging setup which is pretty easy to configure if you are on a MAC or a linux desktop.

您可以使用Firephp作为firebug的附加组件在与javascript相同的环境中调试php。

我还使用前面提到的Xdebug来分析php。

print_r() +1。使用它来转储对象或变量的内容。为了使它更具可读性,使用pre标记,这样你就不需要查看源代码了。

echo '<pre>';
print_r($arrayOrObject);

还有var_dump($thing) -这对于查看子事物的类型非常有用

我使用Netbeans和XDebug。 在它的网站上查看如何配置它的文档。 http://php.netbeans.org/

Xdebug和用于notepad++的DBGp插件用于繁重的bug查找,FirePHP用于轻量级的东西。又快又脏?没有什么比dBug更好的了。