Debugging PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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?.


Re: Debugging PHP


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 ( /).  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.

Re: Debugging PHP

Dave Moore wrote:

Quoted text here. Click to load it

Put this at the top of your PHP script:


phil [dot] ronan @ virgin [dot] net /

Re: Debugging PHP

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.

Re: Debugging PHP

Quoted text here. Click to load it

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

< Space: disk usage analysis tool

Re: Debugging PHP

On Sat, 30 Apr 2005 20:05:37 +0100, Andy Hassall wrote:
Quoted text here. Click to load it

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

  error_reporting = E_ALL|E_STRICT

Firefox Web Browser - Rediscover the web - /
Thunderbird E-mail and Newsgroups - /

Re: Debugging PHP

People should use whatever settings that's helpful. Personally I
program with E_WARNING off too.

Re: Debugging PHP

Quoted text here. Click to load it

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.

Re: Debugging PHP

Hi Dave,

The following is not a debugger, but it can be very helpfull nevertheless:
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 :-(((


Henk Verhoeven,

Dave Moore wrote:
Quoted text here. Click to load it

Re: Debugging PHP

Zend Studio has an excellent debugger, check it out at:">

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).

Re: Debugging PHP

On 1 May 2005 01:27:21 -0700, wrote:
Quoted text here. Click to load it

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 - /
Thunderbird E-mail and Newsgroups - /

Re: Debugging PHP

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

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 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.

Re: Debugging PHP

Dave Moore wrote:
Quoted text here. Click to load it

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


Site Timeline