|
Whether you're a PHP newbie or a wizard, your programs are goingtohave bugs in them. Nobody's perfect. This article gives yousometechniques for finding and fixing the problems in your programs. Itcovers three topics:
- How to get the PHP interpreter to report the errors that interest you.
- How to locate basic syntax errors in your program.
- How to check the values of variables as your program is running.
Configuring Error Reporting
Firstof all, you need to configure the PHP interpreter so thatwhen an errorhappens, you can see information about it. Theerror info can be sentalong with program output to the webbrowser. It can also be included inthe web server error log. A commonway to set things up is to have erroroutput go to the web browserwhen you're debugging your program, andthen to the web server errorlog once the program is finished and(supposedly) workingproperly. That way, web site users can't see anypotentially sensitivedata included with error output.
To make error messages display in the browser, set thedisplay_errors configuration directive to On. Tosend errors to the web server error log, set log_errors toOn. You can set them both to On if you want errormessages in both places.
An error message that the PHP interpreter generatesfalls into one of five different categories:
- Parse error:A problem withthe syntax of your program, such as leaving a semicolonoff of the end ofa statement. The interpreter stops running yourprogram when itencounters a parse error.
- Fatal error: Asevere problemwith the content of your program, such as calling afunction that hasn'tbeen defined. The interpreter stops running yourprogram when itencounters a fatal error.
- Warning: Anadvisory from theinterpreter that something is fishy in your program,but theinterpreter can keep going. Using the wrong number of argumentswhenyou call a function causes a warning.
- Notice: A tipfrom the PHPinterpreter, playing the role of Miss Manners. For example,printing avariable without first initializing it to some valuegenerates anotice.
- Strict notice: An admonishment fromthe PHP interpreterabout your coding style. Most of these have to dowith esotericfeatures that changed between PHP 4 and PHP 5, so you'renot likely torun into them too much.
More @ http://www.onlamp.com/pub/a/php/2004/08/12/DebuggingPHP.html
|
|