No matter how good you are at using the debugging methods listed above, you are almost certainly much less effective at debugging than someone who is using debugging software to find their problems. While debuggers don't automatically point you to errors in your script, they do allow you to step through your code line by line, examine variables as you go, change the value of variables on the fly at runtime, check the contents of your output buffer, and more.

Of all these, just being able to select a line of your script and say "Execute until here" is the best. These script pause markers are called "breakpoints", and you can place as many of them as you want in your scripts. When the scripts are run through your debugger, it will automatically stop when the breakpoint is reached, allowing you to check the values of all the variables in your script to make sure things are going as you expect.

If you work on a project of any level of complexity over 100 lines of code, you should consider using a debugger, however there are several major debuggers to choose from. Previous to PHP 5.6, arguably the most popular was Xdebug (available from but from PHP 5.6 onwards there is one built right in: phpdbg. This is distributed as a SAPI module (just like PHP CLI and PHP for Apache), so you run your script directly into the debugger and it handles the rest.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Custom error handlers >>

Previous chapter: Backtracing your code

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.