PHP Predefined Error Constants

Few days before, we have seen about PHP errors which are classified by the time of occurrence, recovery possibilities and etc. We can decide and control, which of these errors should be displayed on the time of its occurrence, by using predefined constants available in PHP represented as error code or error constants.

php_predefined_error_constants

Let us look into the following table to see the available error constants for the PHP errors classified based on the time of their occurrence.

Fatal Error Warning Notice Parse Error
E_ERROR
runtime error;
cannot be recovered;
will halt execution;
E_WARNING
runtime error;
non-fatal;
wont halt execution;
E_NOTICE
runtime error;
anticipate error caution;
wont halt execution;
E_PARSE
compile time error;
generated by parser;
E_CORE_ERROR
start up error;
generated by PHP core;
E_CORE_WARNING
start up non-fatal error;
generated by PHP core;
   
E_COMPILE_ERROR
compile time error;
generated by Zend Scripting Engine;
E_COMPILE_WARNING
compile time error;
generated by Zend Scripting Engine;
   
E_USER_ERROR
runtime error;
generated by user by trigger_error();
E_USER_WARNING
runtime non-fatal error;
generated by user by trigger_error();
E_USER_NOTICE
similar to E_NOTICE;
generated by user by trigger_error();
 
    E_DEPRECATED
runtime error;
anticipate caution for deprecated methods;
 
    E_USER_DEPRECATED
Like E_DEPRECATED;
generated by user by trigger_error();
 

Other PHP Error Constants

There are some more predefined error constants based on the possibility of error recovery or on providing suggestions to refine our code. These are,

  • E_RECOVERABLE_ERROR – This code is to catch the fatal error by using set_error_handler() function. It will not halt execution unless otherwise the error is not caught by the handler.
  • E_STRICT – This code will display suggestions or warnings if any, to change our code into standard and upgraded form.
  • E_ALL – This code is to display all the available error discussed above as a whole except E_STRICT. But, as of PHP version 5.4.0,  E_STRICT is also included with E_ALL.

These error constants can only be specified with php.ini file to control the visibility of corresponding error. We can found any combination of there error constants with INI supported operators, that is limited with, bitwise (OR, XOR, AND, NOT) and boolean NOT. For example,

error_reporting = E_ALL | E_STRICT

Meaning that, it allows to display the error whether it is either of the above classification including the warning notices that is generated for anticipating cautions to change code as per the coding standards.

This PHP code tutorial was published on June 23, 2013.

↑ Back to Top