Error reporting with PHP
Last Updated on: March 13, 2023
When you are working on your website, you will sometimes want to change the level of error reporting that your code returns.
This is a great way to get full diagnostic information to fix a problem in your latest piece of code, but be careful only to show error reporting on your test site and not on your live site. The current error logging level for your site is set in php.ini like this:
The integer value used will display all error messages below that value, but the maximum error level increases with time as new errors are added. To avoid missing out on any new errors, you could use a numeric value, like-1, instead of the constant E_ALL to include all errors.
// Turn off error reporting error_reporting(0); // Just get simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Change it to include notices as well error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Change it for all errors except the notices (default PHP setting) error_reporting(E_ALL ^ E_NOTICE); // Now get all error reports error_reporting(E_ALL); // Another way to report all error error_reporting(-1); // An alternative way to set it in the php.ini file ini_set('error_reporting', E_ALL);
If you use the error_reporting() function without input, it will just return the current error reporting level.