| only for RuBoard - do not distribute or recompile |
You can set the error reporting settings globally, in your php.ini file or on a per script basis.
To alter the error reporting for all scripts, you can modify these four lines in the default php.ini file:
error_reporting = E_ALL & ~E_NOTICE display_errors = On log_errors = Off track_errors = Off
The default global settings are to
report all errors except notices
output error messages as HTML to standard output
not log error messages to disk
not track errors, storing the error in the variable $php_errormsg
The most likely change you are to make is to turn the error reporting level up to E_ALL. This will result in many notices being reported, for incidents that might indicate an error, or might just result from the programmer taking advantage of PHP's weakly typed nature and the fact that it automatically initializes variables to 0.
While debugging, you might find it useful to set the error_reporting level higher. In production code, if you are providing useful error messages of your own, it might be more professional looking to turn display_errors off and to turn log_errors on, while leaving the error_reporting level high. You will then be able to refer to detailed errors in the logs if problems are reported.
Turning track_errors on might help you to deal with errors in your own code, rather than letting PHP provide its default functionality. Although PHP provides useful error messages, its default behavior looks ugly when things go wrong.
By default, when a fatal error occurs, PHP will output the following:
<br> <b>Error Type</b>: error message in <b>path/file.php</b> on line <b>lineNumber</b><br>
and stop executing the script. For nonfatal errors, the same text is output, but execution is allowed to continue.
This HTML output makes the error stand out, but looks poor. The style of the error message is unlikely to fit the rest of the site's look. It might also result in Netscape users seeing no output at all if the page's content is being displayed within a table. This is because HTML that opens but does not close table elements, such as
<table> <tr><td> <br> <b>Error Type</b>: error message in <b>path/file.php</b> on line <b>lineNumber</b><br>
will be rendered as a blank screen by Netscape.
We do not have to keep PHP's default error handling behavior, or even use the same settings for all files. To change the error reporting level for the current script, you can call the function error_reporting().
Passing an error report constant, or a combination of them, sets the level in the same way that the similar directive in php.ini does. The function returns the previous error reporting level. A common way to use the function is like this:
// turn off error reporting $old_level = error_reporting(0); // here, put code that will generate warnings // turn error reporting back on error_reporting($old_level);
This code snippet will turn off error reporting, allowing us to execute some code that is likely to generate warnings that we do not want to see.
Turning off error reporting permanently is a bad idea as it makes it difficult to find your coding errors and fix them.
| only for RuBoard - do not distribute or recompile |