Specifications

Turning track_errors on might help you to deal with errors in your own code, rather than let-
ting 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 sites look. It might also result in Netscape users seeing no output
at all if the pages 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 PHPs 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.
Debugging
C
HAPTER 23
23
DEBUGGING
491
29 7842 CH23 3/6/01 3:41 PM Page 491