How to debug?

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

Threaded View
How can I debug a PHP program at all? Can/should I use a pop up a message on
the screen showing a variable? Or is there a better way of testing the code?

How can I pop up a message any way?

Thanks a lot

Re: How to debug?

John wrote:
Quoted text here. Click to load it

You can't popup a message.  PHP is server side and popups are client side.

You can echo (or print) variables.  Or you can use an IDE such as the  
ZEND debugger (expensive, but worth it if you do a lot of PHP).

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: How to debug?

Hi John

A couple of thoughts/options off the top of my head...

1) Use a high-end IDE like Zend Studio or ActiveState Komodo, which have  
integrated debugging (my preference is Komodo)

2) Start developing using the Smarty templating engine, -- it has a debug setting that you can turn on and  
off. When it's on, it will automatically generate JavaScript pop-up  
windows showing variables

3) Start doing XP-style unit testing religiously. Several PHP folks were  
inspired by Java's unit testing module, JUnit. Unfortunately this has  
resulted in more than one project named PHPUnit (one of which is in PEAR  
and distributed with PHP). IMHO, there is a better option, called  
SimpleTest, which, contrary to it's name, has more of JUnit's feature-
set than either of the PHPUnits. And a great tutorial too.

It can be a bit confusing at first, but once you start unit testing,  
your debugging sessions will be practically stress-free. I no longer  
program without it.

Hope this helps,
GC says...
Quoted text here. Click to load it

Re: How to debug?

John wrote:
Quoted text here. Click to load it

There are quite a few PHP IDE/debuggers out there, from very basic ones  
to very advanced. Some are even completely free.

check here:


Re: How to debug?


If you use a lot of functions (like with OOP) you may like to print a  
backtrace. For this you can write a simple error handling function, see , that calls
debug_print_backtrace() (this function is php5 only, but it is also  
available in ).


Henk Verhoeven, (framework, includes error handler (prints a  
backtrace) and unit testing tool)

John wrote:
Quoted text here. Click to load it

Site Timeline