Chapter 3

Debugging PHP Code

IN THIS CHAPTER

Bullet Setting up PHP for debugging

Bullet Examining the PHP error log

Bullet Outputting variable values with echo and print

Bullet Making good use of print_r()

Bullet Getting to know var_dump()

The most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

— BRIAN KERNIGHAN

Debugging — the art, science, and (sometimes) magic of finding and correcting programming errors — is a vital part of all web development. Why? Because no one — not even the nerdiest and most experienced of coders — can write anything moderately complex without introducing an error (or, more likely, a half dozen errors). Programming just works that way. Don’t ask me why because I really have no idea. It just does. So, when some code doesn’t work the first time (or even the tenth time), it doesn’t mean you’re a lousy coder. It just means you’re normal. Believe me, it happens to absolutely everyone who codes.

JavaScript code runs inside the browser, so debugging ...

Get Web Coding & Development All-in-One For Dummies, 2nd Edition 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.