25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

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

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

<strong>PHP</strong> Basics ” 33<br />

Compile-time errors<br />

Fatal errors<br />

Recoverable errors<br />

Warnings<br />

Notices<br />

Errors detected by the parser while it is compiling<br />

a script. Cannot be trapped from within the script<br />

itself.<br />

Errors that halt the execution of a script. Cannot<br />

be trapped.<br />

Errors that represent significant failures, but can<br />

still be handled in a safe way.<br />

Recoverable errors that indicate a run-time fault.<br />

Do not halt the execution of the script.<br />

Indicate that an error condition occurred, but is<br />

not necessarily significant. Do not halt the<br />

execution of the script.<br />

As you can see, it is not always possible for a script to detect a fault and recover from<br />

it. With the exception of parsing errors and fatal errors, however, your script can at<br />

least be advised that a fault has occurred, thus giving you the possibility to handle<br />

failure gracefully.<br />

Error Reporting<br />

By default, <strong>PHP</strong> reports any errors it encounters to the script’s output. Unless you<br />

happen to be in a debugging environment, this is rarely a feature that you will want<br />

to take advantage of: allowing users to see the errors that your scripts encounter is<br />

not just bad form—it could be a significant security issue.<br />

Luckily, several configuration directives in the php.ini file allow you to finetune<br />

how—and which—errors are reported. The most important ones are<br />

error_reporting, display_errors and log_errors.<br />

The error_reporting directive determines which errors are reported by <strong>PHP</strong>. A series<br />

of built-in constants allow you to prevent <strong>PHP</strong> from reporting errors beneath a<br />

certain pre-defined level. For example, the following allows for the reporting of all<br />

errors, except notices:<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

error_reporting=E_ALL & ~E_NOTICE

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

Saved successfully!

Ooh no, something went wrong!