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 at the time of its occurrence, by using predefined constants available in PHP represented as the error code or 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 ErrorWarningNoticeParse Error
runtime error;
cannot be recovered;
will halt execution;
runtime error;
wont halt execution;
runtime error;
anticipate error caution;
wont halt execution;
compile time error;
generated by parser;
start up error;
generated by PHP core;
start up non-fatal error;
generated by PHP core;
compile time error;
generated by Zend Scripting Engine;
compile time error;
generated by Zend Scripting Engine;
runtime error;
generated by user by trigger_error();
runtime non-fatal error;
generated by user by trigger_error();
similar to E_NOTICE;
generated by user by trigger_error();
runtime error;
anticipate caution for deprecated methods;
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 a php.ini file to control the visibility of corresponding error. We can found any combination of their 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 the code as per the coding standards.

Please follow and like us:

By Rodney

I’m Rodney D Clary, a web developer. If you want to start a project and do a quick launch,I am available for freelance work.

One thought on “PHP Predefined Error Constants

  1. Sets the maximum length of log_errors in bytes. The value “0” can be used to not apply any maximum length at all. This length is applied to logged errors, displayed errors, and also to $php_errormsg (available since PHP 4.3)

Leave a Reply

Your email address will not be published. Required fields are marked *