By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

Debugging PHP

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
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/
Jul 17 '05 #2

P: n/a
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.

Jul 17 '05 #3

P: n/a
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

Jul 17 '05 #4

P: n/a
That won't help when there's a parse error. The solution here is to
make sure display_error is set to "on" in php.ini and error_reporting
to something sensible, like E_ALL & ~E_NOTICE.

Jul 17 '05 #5

P: n/a
On 30 Apr 2005 11:26:43 -0700, "Chung Leong <ch***********@hotmail.com>"
<ch***********@hotmail.com> wrote:
That won't help when there's a parse error. The solution here is to
make sure display_error is set to "on" in php.ini and error_reporting
to something sensible, like E_ALL & ~E_NOTICE.


E_ALL is sensible whilst developing; don't turn off E_NOTICE.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #6

P: n/a
On Sat, 30 Apr 2005 20:05:37 +0100, Andy Hassall wrote:
to something sensible, like E_ALL & ~E_NOTICE.


E_ALL is sensible whilst developing; don't turn off E_NOTICE.


Maybe even turn om E_STRICT (not included in E_ALL):

error_reporting = E_ALL|E_STRICT
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #7

P: n/a
Zend Studio has an excellent debugger, check it out at:

www.zend.com

Xdebug is your other option, basically both "inject" themselves into
PHP and you (the programmer) can debug via their perspective clients
(which listen for their requests on specific ports on your machine,
different than MS Studio debuggers).

Jul 17 '05 #8

P: n/a
On 1 May 2005 01:27:21 -0700, jo*******@gmail.com wrote:
Zend Studio has an excellent debugger [...] Xdebug is your other option


How about phpeclipse, apparently it includes a debugger (from eclipse,
or php-specific?), do you have any experience with that?
--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Jul 17 '05 #9

P: n/a
People should use whatever settings that's helpful. Personally I
program with E_WARNING off too.

Jul 17 '05 #10

P: n/a
Dave Moore wrote:
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?.


I evaluated NuSphere phped and Zend Studio last year. They both do have
debugging support, but I like phped better. Generally, it's better and
more responsitive while Zend Studio is slow and resource hog. I
purchased phped then and it helps me to write better code.

Both are nice products however, you may want to try them on your
project.

-Erich

Jul 17 '05 #11

P: n/a
Sorry for the late reply.

No unfortunately I do not. I can however tell you that Zend is probably
your best bet as they an inherit better understanding of the Zend
Engine (2), which is a core part of PHP. Because of this fact, I trust
it to be more "up to date" and better supported in terms of future PHP
(I'm a bleeding edge kind of guy, so that might not be the case with
you).

Prices are about the same, I think Zend might provide support longer
support for you though, it's been a while since I checked the pricing
charts though. Well I take that back, I don't really remember as my
company bought the license on my behalf, all I know is that I have had
complimentary product updates thus far. ;-)

The debugger I can compare Zend Studio to is MS Visual Studio, in that
they basically have the same features and interaction (right down to
the shortcut keys if you select the MS VS keyboard layout option).

However, I did run into some trivial problems with getting things
working at home with the debugger, due to my router and some drive
mapping, but at the end I got it working just as I'd like...plus the
Firefox toolbar just seals the deal for me :-)

Zend Enhanced support is really reliable and some of the most
knowledgable people I have worked with in support. I've heard good
things about eclipse from fellow programmers at work, but I couldn't
even get it to start up on my machine so I can't comment personally.

Jul 17 '05 #12

P: n/a
Chung Leong <ch***********@hotmail.com> wrote:
That won't help when there's a parse error. The solution here is to
make sure display_error is set to "on" in php.ini and error_reporting
to something sensible, like E_ALL & ~E_NOTICE.


if you're looking to debug your scripts i strongly advise you to
download Komodo personal, search on the internet, and get a premotion
code and a free copy, works with the dbg debugger and is flawless for me.
Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.