如何调试PHP脚本?

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

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


当前回答

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

其他回答

手动调试对我来说通常更快——var_dump()和debug_print_backtrace()是你需要用来武装你的逻辑的所有工具。

1)使用print_r()。在TextMate中,我有一个'pre'的片段,它扩展为:

echo "<pre>";
print_r();
echo "</pre>";

2)我使用Xdebug,但还不能让GUI在我的Mac上正常工作。它至少打印出一个可读的堆栈跟踪版本。

如果您不想弄乱输出,输出缓冲是非常有用的。我在一行代码中做到了这一点,我可以随意注释/取消注释

 ob_start();var_dump(); user_error(ob_get_contents()); ob_get_clean();

Print_r (debug_backtrace());

或者类似的东西:-)

我使用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.