docs:programming:php:error_handling

This is an old revision of the document!


Error Handling

Normally, when an error occurs in a PHP script, the error message is inserted into the script's output. If the error is fatal, the script execution stops.

By default, all conditions except runtime notices are caught and displayed to the user. You can change this behavior globally in your php.ini file with the error_reporting option. You can also locally change the error-reporting behavior in a script using the error_reporting() function.

With both of these, you set the conditions that are caught and displayed by using the various bitwise operators for combinations.

Example - all error-level options:
(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)

Example - all options except runtime notices:
(E_ALL & ~E_NOTICE)

Value Meaning
E_ERROR Runtime errors
E_WARNING Runtime warnings
E_PARSE Compile-time parse errors
E_NOTICE Runtime notices
E_CORE_ERROR Errors generated internally by PHP
E_CORE_WARNING Warnings generated internally by PHP
E_COMPILE_ERROR Errors generated internally by the Zend scripting engine
E_COMPILE_WARNING Warnings generated internally by the Zend scripting engine
E_USER_ERROR Runtime errors generated by a call to trigger_error()
E_USER_WARNING Runtime warnings generated by a call to trigger_error()
E_USER_NOTICE Runtime warnings generated by a call to trigger_error()
E_ALL All of the above options
  • disable error messages for a single expression:
    • $value = @(2 / 0);
  • turn off error reporting entirely:
    • error_reporting(0);

trigger_error(message [, type]);

* the second parameter is the condition level, which is either E_USER_ERROR, E_USER_WARNING, or E_USER_NOTICE (the default)

FIXME

  • docs/programming/php/error_handling.1174712215.txt.gz
  • Last modified: 2008/08/03 00:25
  • (external edit)