Debugging

Every programmer is constantly on the lookout for a better way to minimize errors and problems in their scripts. Unfortunately, most programmers learn debugging through sheer trial and error—and lots of it. Here are some tips for debugging your scripts:

  • View the HTML source when a problem happens. Some browsers—for example, Netscape Navigator—will show a blank page even when a PHP error occurs toward the end of a page. Viewing the source may be the only way to see what the issue is.

  • Use a text editor that checks for balanced parentheses, braces, tags, quotation marks, and more.

  • Use reverse testing when logical errors occur. Reverse testing is the method of switching your conditionals. For example,

    if ($variable = 5) { ... 
    

    may not seem ...

Get PHP Advanced for the World Wide Web: Visual QuickPro Guide 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.