Skip to content

Available predefined error constants for the php

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
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();
error constants

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.

1 thought on “Available predefined error constants for the php”

  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 *