调试PHP [英] Debugging PHP

查看:46
本文介绍了调试PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我刚刚开始编写PHP脚本。我想知道是否有任何明智的调试工具,我不知道。基本上,我通常的b
开发过程包括编写脚本然后使用IE进行测试。

然而,似乎除非PHP是完美的(即没有任何
语法错误)然后什么都没有输出到浏览器。个人

我发现这非常令人沮丧,因为不知道错误在哪里。然后我开始进行疯狂的追逐,进行各种调试''echo''

语句并注释掉各种PHP代码,直到某些东西

有效。必须有比这更好的方法。


我可以做出任何选择或选择给我一些调试

输出吗?我可以使用解析器来确保在运行脚本之前没有语法上的

错误吗?或者我可以使用PHP调试器通过命令命令执行步骤




谢谢,

Dave

解决方案

Dave Moore写道:

我可以做出任何选择或选择我有些调试输出?




把它放在PHP脚本的顶部:


error_reporting(E_ALL );


-

phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


Dave,


将error_reporting(E_ALL)直接放在你的脚本中可能不是必需的
。默认情况下,此值已在PHP中设置。使用

phpinfo()查看是否。


最好的办法是输入echo,print或fwrite(用于命令行) />
接口)在关键点的脚本中。这将帮助您通过它走




有几个IDE具有调试功能。即使能够运行脚本或逐步执行它们,它们也可能是



有一个免费的PHP IDE( http://syn.sourceforge.net/) 。它是一个很好的编辑器,带有Syntax高亮显示等等。它还具有

调试功能。但是,我从来没有运气这个方面工作并放弃它。但是,它是一个体面的编辑。我不会在随机时间看起来像是一个过程和内存占用。


嗨Dave,


以下不是调试器,但它可能非常有用:
http://nl2.php.net/manual/en/functio...-backtrace.php

将数组提供给print_r,看看你到底得到了什么。那么它应该很难建立一个花哨的回溯打印功能。


如果你做了错误处理功能并设置了它的名字

set_error_handler你可以让它在

传统错误信息下打印一个回溯。 (在手册中搜索set_error_handler)


限制:它不适用于致命错误 - 这个人确定php开发人员不需要处理错误致命的错误

犯了一个致命的错误: - ((


问候,


Henk Verhoeven,
www.phpPeanuts.org


Dave Moore写道:

大家好,我刚刚开始编写PHP脚本。我想知道是否有任何合理的调试工具我不是基本上,我通常的开发过程包括编写脚本然后使用IE进行测试。
但是,看起来除非PHP是完美的(即没有任何语法错误)然后什么都没有输出到浏览器。个人
我发现这非常令人沮丧,因为没有关于错误在哪里的线索。我
n开始疯狂追逐各种调试''echo''
语句,并注释掉各种PHP代码块直到
有效。必须有比这更好的方法。

我可以做出任何选择或选择来给我一些调试输出吗?在运行脚本之前,我是否可以使用解析器来确保没有语法错误?或者我可以使用PHP调试器通过命令执行代码命令?

谢谢,
Dave



Hi All,
I''ve just started writing PHP scripts. I was wondering whether there was
any sensible debugging facilities that I''m not aware of. Basically, my usual
development procedure involves writing the script and then testing using IE.
However, it appears that unless the PHP is perfect (ie. devoid of any
syntactical errors) then nothing at all is output to the browser. Personally
I find this very frustrating as there''s no clue as to where the error is. I
then commence on a wild goose chase putting in various debugging ''echo''
statements and commenting out various chunks of PHP code until something
works. There must be a better approach than this.

Are there any option or selections I can make to give me some debugging
output?. Is there a parser I can use to ensure there are no syntactical
errors before running the script?. Or a PHP debugger I can use to step
through the code command by command?.

Thanks,
Dave

解决方案

Dave Moore wrote:

Are there any option or selections I can make to give me some debugging
output?



Put this at the top of your PHP script:

error_reporting(E_ALL);

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


Dave,

Putting error_reporting(E_ALL) directly in your script may not be
necessary. By default, this value is already set in PHP. Use
phpinfo() to find out if it is.

Your best bet is to put in echo, print, or fwrite(for command line
interface) in your script at key points. This will help you "walk"
through it.

There are several IDE''s that have debugging capabilities. They may
even be able to run the script or step through it.

There is a free IDE for PHP (http://syn.sourceforge.net/). It is a
decent editor with Syntax highlighting and the such. It also has
debugging capabilities. However, I never had luck getting this aspect
to work and gave up on it. But, it is a decent editor. I would not
that it seems to be a bit of a process and memory hog at random times.


Hi Dave,

The following is not a debugger, but it can be very helpfull nevertheless:
http://nl2.php.net/manual/en/functio...-backtrace.php
feed the array to print_r to see what exactly you get. Then it should
not be hard to build a fancy backtrace printing function.

If you make an error handling function and set its name with
set_error_handler you can make it print a backtrace below the
coventional error info. (search the manual for set_error_handler)

Limitation: it will not work for fatal errors - imho the person that
decided that php developers do not need error handling for fatal errors
made a fatal mistake :-(((

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

Dave Moore wrote:

Hi All,
I''ve just started writing PHP scripts. I was wondering whether there was
any sensible debugging facilities that I''m not aware of. Basically, my usual
development procedure involves writing the script and then testing using IE.
However, it appears that unless the PHP is perfect (ie. devoid of any
syntactical errors) then nothing at all is output to the browser. Personally
I find this very frustrating as there''s no clue as to where the error is. I
then commence on a wild goose chase putting in various debugging ''echo''
statements and commenting out various chunks of PHP code until something
works. There must be a better approach than this.

Are there any option or selections I can make to give me some debugging
output?. Is there a parser I can use to ensure there are no syntactical
errors before running the script?. Or a PHP debugger I can use to step
through the code command by command?.

Thanks,
Dave



这篇关于调试PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆