如何调试PHP脚本?
我知道基本的调试,如使用错误报告。PHPEclipse中的断点调试也非常有用。
在phpStorm或任何其他IDE中调试的最佳方法(就快速和简单而言)是什么?
如何调试PHP脚本?
我知道基本的调试,如使用错误报告。PHPEclipse中的断点调试也非常有用。
在phpStorm或任何其他IDE中调试的最佳方法(就快速和简单而言)是什么?
当前回答
根据问题的不同,我喜欢将error_reporting(E_ALL)与echo测试混合使用(以找到最初发生错误的违规行/文件;你知道它并不总是行/文件php告诉你对吗?),IDE大括号匹配(解决“解析错误:语法错误,意外的$end”问题),和print_r();退出;转储(真正的程序员查看源代码;p)。
你也不能用“memory_get_usage();”和“memory_get_peak_usage();”来打败phpdebug(检查sourceforge)来找到问题区域。
其他回答
在某种程度上,这取决于事情的走向。这是我尝试分离的第一件事,然后在必要时使用echo/print_r()。
注:你们知道你可以把true作为第二个参数传递给print_r(),它会返回输出而不是打印它吗?例如:
echo "<pre>".print_r($var, true)."</pre>";
1)使用print_r()。在TextMate中,我有一个'pre'的片段,它扩展为:
echo "<pre>";
print_r();
echo "</pre>";
2)我使用Xdebug,但还不能让GUI在我的Mac上正常工作。它至少打印出一个可读的堆栈跟踪版本。
我使用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做了一些微处理器编程,甚至都不会使用它,我才完全理解这一点。
在生产环境中,我使用error_log()将相关数据记录到服务器的错误日志中。