Error handling is very important in any programming language. In PHP error level categorized in various kind of error and it’s define all type of error like notice, warning and fatal errors. There are sixteen type of errors level available in PHP. In this tutorial we have mentioned values and constant which can be used in PHP for error reporting using error_reporting() function.
E_ERROR (1) - It’s a Fatal run-time errors. Execution of the script is stopped.
E_WARNING (2) - It’s a Run-time warnings. Execution of the script is not stopped.
E_PARSE (4) - It’s a compile-time parse error. This errors should only be generated by the parser.
E_NOTICE (8) - It’s a run-time notice indicating that the script encountered something that could possibly an error, however It could also occur when running a script normally.
E_CORE_ERROR (16) - It’s a Fatal errors and occur during PHP’s initial startup.
E_CORE_WARNING (32) - It’s a warning and occur during PHP’s initial startup.
E_COMPILE_ERROR (64) – A fatal error that occur when the script was being compiled. Except it is generated by the Zend Scripting Engine.
E_COMPILE_WARNING (128) - A warning (non-fatal error) that occur when the script was being compiled. Except it is generated by the Zend Scripting Engine.
E_USER_ERROR (256) – It’s user-generated error message like an E_ERROR. It is generated by the PHP code using the function trigger_error().
E_USER_WARNING (512) - It’s user-generated warning message like an E_WARNING. It is generated by the PHP code using the function trigger_error().
E_USER_NOTICE (1024) - A user-generated notice message like an E_NOTICE. It is generated by the PHP code using the function trigger_error().
E_STRICT (2048) - Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
E_RECOVERABLE_ERROR (4096) - A catchable fatal error. It indicates that a probably dangerous error occurred, but did not leave the Engine in an unstable state.
E_DEPRECATED (8192) – It’s a Run-time notices.
E_USER_DEPRECATED (16384) - User-generated warning message. This is like an
E_ALL (32767) - All errors and warnings
SOURCE - http://php.net/manual/en/errorfunc.constants.php
Basic Usage of PHP’s error reporting
If you want to hide all type of error , warning of notice then just use error_reporting() as mentioned below:
If you want to show all type of error , warning of notice then just use error_reporting() as mentioned below:
Advanced Usage of PHP’s error reporting
If you want to show warnings and errors only then use
error_reporting(E_ERROR | ERROR_WARNING);
if you want to show all types but want o hide notices then user
error_reporting(E_ALL ^ E_NOTICE);