3.10. Debugging PHP

After you have learned to write simple PHP applications, it is time to verify that your applications work. Therefore debugging has to be done.

In PHP3 a debugger was included that was able to send data to a TCP port where it can easily be monitored with the help of a listener.

Unfortunately in PHP this debugger can only be used if you buy the ZEND IDE (http://www.zend.com/store/). Some other debuggers are available for PHP, but we do not cover these products in this book. However, in this section you learn to debug PHP programs using PHP onboard tools.

The easiest way to debug PHP code is to write a debugging function. Let's assume that you want to monitor the content of $i:

 <?php include ("debug.php"); for ($i=1; $i <= 5; ...

Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.