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 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(); |
There are some more predefined error constants based on the possibility of error recovery or on providing suggestions to refine our code. These are,
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.