Chapter 12. Debugging
Programs rarely work correctly the first time. This chapter shows you some techniques for finding and fixing the problems in your programs. When youâre just learning PHP, your programs are probably simpler than the programs that PHP wizards write. The errors you get, however, generally arenât much simpler, and you have to use the same tools and techniques to find and fix those errors.
Controlling Where Errors Appear
Many things can go wrong in your program that cause the PHP interpreter to generate an error message. You have a choice about where those error messages go. The messages can be sent along with other program output to the web browser. They can also be included in the web server error log.
A useful way to configure an error message display is to have the errors displayed on screen when youâre developing a PHP program, and then sent to the error log once youâre done development and people are actually using the program. While youâre working on a program, itâs helpful to see immediately that there was a parse error on a particular line, for example. But once the program is (supposedly) working so that your coworkers or customers can use it, such an error message would be confusing to them.
To make error messages display in the browser, set the display_errors
configuration directive to On
. To send errors to the
web server error log, set log_errors
to On
. You can set them both to On
if you
want error messages in both places.
An error message ...
Get Learning PHP 5 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.