There are two basic types of errors in PHP: the traditional, procedural error, which has been part of the PHP framework since the beginning, and a new OOP- (object-oriented programming) based exception handling system introduced with PHP5. Although exceptions provide a greater degree of flexibility in handling deliberately raised errors generated by your script, you will undoubtedly need to be familiar with the simpler procedural error system so that you can effectively handle errors generated by PHP's sizeable library of non-OOP functions. Error TypesPHP's error system defines 12 unique types of errors, which can be summarized into three basic categories: Informational, Actionable, and Fatal. Each can occur at any time from startup and compilation to runtime. Informational errors are not truly "errors" as such, but rather the engine trying to let you know that although it can process the source code you've provided, something seems amiss and the referenced code should be looked at. Examples of informational errors include undefined constants, attempting to read an undefined variable, defining a class property in PHP5 using var instead of public, protected, or private, and about 200 other less-common cases. Most informational errors can be avoided through the use of explicit programming techniques, but are ultimately harmless to the execution of a script. Informational errors include the following:
Actionable errors indicate that something clearly wrong has happened and that your script may need to alter its behavior or even back out of its current processing and exit with an informative message to the user. These types of errors occur when expected resources are unavailable (file not found, database not responding, and so on), data passed to a function is outside of the expected range of values, when security settings prevent the current script from performing a specific action, or in more than 1,000 other situations. Actionable errors include the following:
Fatal errors occur when something so terrible has happened during the execution of your script, or during the startup of the PHP interpreter, that further processing simply cannot continue. When a fatal error occurs, PHP displays and/or logs an error message (depending on php.ini settings), and stops execution of your script. A fatal error may occur because PHP was unable to load a required module, the requested script could not be correctly read, or an instruction was encountered that could not be processed (for example, calling an undefined function). Fatal errors include the following:
|