Home arrow PHP arrow Page 2 - Error and Exception Handling in PHP

Configuration Directives - PHP

Mistakes are inevitable, in life, programming, and application submissions. You can prepare for errors by making sure your application is designed to respond to them. This two-part article explains how PHP handles errors. It is excerpted from chapter 8 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

TABLE OF CONTENTS:
  1. Error and Exception Handling in PHP
  2. Configuration Directives
  3. Displaying Errors to the Browser
  4. Error Logging
  5. Initializing PHP’s Logging Facility
  6. Sending a Message to the Logging Destination
By: Apress Publishing
Rating: starstarstarstarstar / 2
December 31, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Numerous configuration directives determine PHP’s error-reporting behavior. Many of these directives are introduced in this section.

Setting the Desired Error Sensitivity Level

Theerror_reportingdirective determines the reporting sensitivity level. Fourteen separate levels are available, and any combination of these levels is valid. See Table 8-1 for a complete list of these levels. Note that each level is inclusive of all levels residing below it. For example, theE_ALLlevel reports any messages resulting from the 13 other levels residing below it in the table.

Table 8-1. PHP’s Error-Reporting Levels  

Error Level

Description

E_ALL

All errors and warnings

E_COMPILE_ERROR

Fatal compile-time errors

E_COMPILE_WARNING

Compile-time warnings

E_CORE_ERROR

Fatal errors that occur during PHP’s initial start

E_CORE_WARNING

Warnings that occur during PHP’s initial start

E_ERROR

Fatal run-time errors

E_NOTICE

Run-time notices

E_PARSE

Compile-time parse errors

E_RECOVERABLE_ERROR

Near-fatal errors (introduced in PHP 5.2)

E_STRICT

PHP version portability suggestions (introduced in PHP 5.0)

E_USER_ERROR

User-generated errors

E_USER_NOTICE

User-generated notices

E_USER_WARNING

User-generated warnings

E_WARNING

Run-time warnings

Introduced in PHP 5,E_STRICTsuggests code changes based on the core developers’ determinations as to proper coding methodologies and is intended to ensure portability across PHP versions. If you use deprecated functions or syntax, use references incorrectly, usevarrather than a scope level for class fields, or introduce other stylistic discrepancies,E_STRICTcalls it to your attention. In PHP 6,E_STRICTis integrated intoE_ALL; therefore, when running PHP 6, you’ll need to set theerror_reportingdirective toE_ALLin order to view these portability suggestions.


Note  Theerror_reportingdirective uses the tilde character (~) to represent the logical operatorNOT.


During the development stage, you’ll likely want all errors to be reported. Therefore, consider setting the directive like this:

error_reporting = E_ALL

However, suppose that you were only concerned about fatal run-time, parse, and core errors. You could use logical operators to set the directive as follows:

error_reporting E_ERROR | E_PARSE | E_CORE_ERROR

As a final example, suppose you want all errors reported except for user-generated ones:

error_reporting E_ALL & ~(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE)

As is often the case, the name of the game is to remain well-informed about your application’s ongoing issues without becoming so inundated with information that you quit looking at the logs. Spend some time experimenting with the various levels during the development process, at least until you’re well aware of the various types of reporting data that each configuration provides.



 
 
>>> More PHP Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: