05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

By default, all conditions except runtime notices are caught and displayed to the<br />

user. You can change this behavior globally in your php.ini file with the error_<br />

reporting option. You can also locally change the error-reporting behavior in a script<br />

using the error_reporting( ) function.<br />

With both the error_reporting option and the error_reporting( ) function, you<br />

specify the conditions that are caught and displayed by using the various bitwise<br />

operators to combine different constant values, as listed in Table 13-1. For example,<br />

this indicates all error-level options:<br />

(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)<br />

while this indicates all options except runtime notices:<br />

(E_ALL & ~E_NOTICE)<br />

If you set the track_errors option on in your php.ini file, a description of the current<br />

error is stored in $<strong>PHP</strong>_ERRORMSG.<br />

Table 13-1. Error-reporting values<br />

Value Meaning<br />

E_ERROR Runtime errors<br />

E_WARNING Runtime warnings<br />

E_PARSE Compile-time parse errors<br />

E_NOTICE Runtime notices<br />

E_CORE_ERROR Errors generated internally by <strong>PHP</strong><br />

E_CORE_WARNING Warnings generated internally by <strong>PHP</strong><br />

E_COMPILE_ERROR Errors generated internally by the Zend scripting engine<br />

E_COMPILE_WARNING Warnings generated internally by the Zend scripting engine<br />

E_USER_ERROR Runtime errors generated by a call to trigger_error( )<br />

E_USER_WARNING Runtime warnings generated by a call to trigger_error( )<br />

E_USER_NOTICE Runtime warnings generated by a call to trigger_error( )<br />

E_ALL All of the above options<br />

Error Suppression<br />

You can disable error messages for a single expression by putting the error suppression<br />

operator @ before the expression. For example:<br />

$value = @(2 / 0);<br />

Without the error suppression operator, the expression would normally halt execution<br />

of the script with a “divide by zero” error. As shown here, the expression does<br />

nothing. The error suppression operator cannot trap parse errors, only the various<br />

types of runtime errors.<br />

304 | Chapter 13: Application Techniques<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!