In this tutorial, I will talk about the error_reporting() function in PHP and how to prevent errors printed on a web page if needed.
The error_reporting() function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script. If the optional level is not set, error_reporting() will just return the current error reporting level.
The error reporting level is either an integer representing a bit field, or named constants.
PHP 5.3 or later, the default value is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED. This setting does not show E_NOTICE, E_STRICT and E_DEPRECATED level errors. You may want to show them during development. Prior to PHP 5.3.0, the default value is E_ALL & ~E_NOTICE & ~E_STRICT.
📄 Turn off all error reporting.
📄 Report simple running errors.
📄 error_reporting(E_ERROR | E_WARNING | E_PARSE);
📄 Reporting E_NOTICE can be good too (to report uninitialized variables or catch variable name misspellings ...).
📄 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
📄 Report all errors except E_NOTICE.
📄 error_reporting(E_ALL & ~E_NOTICE);
📄 Report all PHP errors.
-------------- PHP -------------- <?php // Turn off all error reporting. error_reporting(0); ?>