CHAPTER 7 – TYPES OF ERRORS – PHP Errors
The error mechanism in PHP is used by all built-in PHP functions. By default, this simple mechanism prints an error message with file and line number and exits. In the previous section, we saw several examples of PHP errors.
Error Levels PHP errors are categorized by an error level ranging from notices to fatal errors. The error level tells you how serious the error is. Most errors may be caught with a custom error handler, but some are unre- coverable. E_ERROR This is a fatal, unrecoverable error. Examples are out-of-memory errors, uncaught exceptions, or class redeclarations.
E_WARNING This is the most common type of error. It normally signals that some- thing you tried doing went wrong. Typical examples are missing function parameters, a database you could not connect to, or division by zero. E_PARSE Parse errors occur during compilation, and force PHP to abort before exe- cution. This means that if a file fails with a parse error, none of it will be exe- cuted. E_STRICT This error level is the only one not included in the E_ALL constant. The reason for this is to make transition from PHP 4 to PHP 5 easier; you can still run PHP 4 code in PHP 5. E_NOTICE Notices are PHP's way to tell you that the code it runs may be doing something unintentional, such as reading that undefined variable. It is good practice to develop with notices enabled so that your code is "notice-safe" before pushing it live. On your production site, you should completely disable HTML errors. E_CORE_ERROR This internal PHP error is caused by an extension that failed starting up, and it causes PHP to abort. E_COMPILE_ERROR Compile errors occur during compilation, and are a variation of E_PARSE. This error causes PHP to abort. E_COMPILE_WARNING This compile-time warning warns users about deprecated syntax. E_USER_ERROR This user-defined error causes PHP to abort execution. User-defined errors (E_USER_*) are never caused by PHP itself, but are reserved for scripts. E_USER_WARNING This user-defined error will not cause PHP to exit. Scripts may use it to signal a failure corresponding to one that PHP would signal with E_WARNING. E_USER_NOTICE This user-defined notice may be used in scripts to signal possible errors (analogous to E_NOTICE).