我是PHP的新手.这是我的情况.我在vim中编写代码并将其放在/ var/www /下我可以使用
localhost/* .php
在浏览器上运行我的代码.
当我的代码有bug时.它什么都没出来.
如何调试像c ++或java这样的mu代码?
谢谢.
编辑:
一些朋友提供的链接对我没有帮助.我在Linux下.这是胜利.
Thi*_*ish 10
在代码中包含这两行以查看错误类型。
<?php
ini_set("display_errors",1);
error_reporting(E_ALL);
//code goes here
?>
Run Code Online (Sandbox Code Playgroud)
如果在本地主机上,我建议使用firefox或chrome并为mozilla安装firebug,并且chrome获取默认值.请确保在本地主机上您的设置与要上载的服务器匹配,因为这可能会在上线时导致问题.
特别是大多数共享主机在安全模式和输出缓冲关闭时都有PHP,因此如果您使用它,请通过调用ob_start()来调用它; 等等,否则你应该没有问题,学习调试是乐趣的一部分,帮助你学习很多:)
至于php错误只需重新编辑你的php.ini文件,你可以在http://php.net上找到相关信息
快乐的编码
对于更高级的解决方案,您可以使用XDebug扩展PHP.
默认情况下,加载XDebug时,它应该在出现任何致命错误时自动显示回溯.或者您追踪到file(xdebug.auto_trace)以获得整个请求的非常大的回溯或进行分析(xdebug.profiler_enable)或其他设置.如果跟踪文件太大,您可以使用xdebug_start_trace()和xdebug_stop_trace()转储部分跟踪.
安装
使用PECL:
pecl install xdebug
Run Code Online (Sandbox Code Playgroud)
在Linux上:
sudo apt-get install php5-xdebug
Run Code Online (Sandbox Code Playgroud)
在Mac上(使用Homebrew):
brew tap josegonzalez/php
brew search xdebug
php53-xdebug
Run Code Online (Sandbox Code Playgroud)
矿井配置示例:
[xdebug]
; Extensions
extension=xdebug.so
; zend_extension="/YOUR_PATH/php/extensions/no-debug-non-zts-20090626/xdebug.so"
; zend_extension="/Applications/MAMP/bin/php/php5.3.20/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so" ; MAMP
; Data
xdebug.show_exception_trace=1 ; bool: Show a stack trace whenever an exception is raised.
xdebug.collect_vars = 1 ; bool: Gather information about which variables are used in a certain scope.
xdebug.show_local_vars=1 ; int: Generate stack dumps in error situations.
xdebug.collect_assignments=1 ; bool: Controls whether Xdebug should add variable assignments to function traces.
xdebug.collect_params=4 ; int1-4: Collect the parameters passed to functions when a function call is recorded.
xdebug.collect_return=1 ; bool: Write the return value of function calls to the trace files.
xdebug.var_display_max_children=256 ; int: Amount of array children and object's properties are shown.
xdebug.var_display_max_data=1024 ; int: Max string length that is shown when variables are displayed.
xdebug.var_display_max_depth=3 ; int: How many nested levels of array/object elements are displayed.
xdebug.show_mem_delta=0 ; int: Show the difference in memory usage between function calls.
; Trace
xdebug.auto_trace=0 ; bool: The tracing of function calls will be enabled just before the script is run.
xdebug.trace_output_dir="/var/log/xdebug" ; string: Directory where the tracing files will be written to.
xdebug.trace_output_name="%H%R-%s-%t" ; string: Name of the file that is used to dump traces into.
; Profiler
xdebug.profiler_enable=0 ; bool: Profiler which creates files read by KCacheGrind.
xdebug.profiler_output_dir="/var/log/xdebug" ; string: Directory where the profiler output will be written to.
xdebug.profiler_output_name="%H%R-%s-%t" ; string: Name of the file that is used to dump traces into.
xdebug.profiler_append=0 ; bool: Files will not be overwritten when a new request would map to the same file.
; CLI
xdebug.cli_color=1 ; bool: Color var_dumps and stack traces output when in CLI mode.
; Remote debugging
xdebug.remote_enable=off ; bool: Try to contact a debug client which is listening on the host and port.
xdebug.remote_autostart=off ; bool: Start a remote debugging session even GET/POST/COOKIE variable is not present.
xdebug.remote_handler=dbgp ; select: php3/gdb/dbgp: The DBGp protocol is the only supported protocol.
xdebug.remote_host=localhost ; string: Host/ip where the debug client is running.
xdebug.remote_port=9000 ; integer: The port to which Xdebug tries to connect on the remote host.
xdebug.remote_mode=req ; select(req,jit): Selects when a debug connection is initiated.
xdebug.idekey="xdebug-cli" ; string: IDE Key Xdebug which should pass on to the DBGp debugger handler.
xdebug.remote_log="/var/log/xdebug.log" ; string: Filename to a file to which all remote debugger communications are logged.
Run Code Online (Sandbox Code Playgroud)