On a production site, you would most likely want to hide all possible PHP errors, warnings and notices from your users for both usability, presentational and security purposes.
For development and debugging purposes, you would want to turn on error_reporting and display all error messages so that you can debug your code and ensure that it is working as intended. You have to remember that there are different types of PHP errors. Fatal errors literally cease the execution of the script while warnings and notices simply notify you of the possibility of errors or bad programming practice in general.
In this article, I’ll use WordPress as an example. I’ll show you how to turn off error_reporting on your WordPress production site so that users won’t have to look at ugly errors/warnings on your pages. Even though I’ll be using WordPress as an example, this method can be applied to any other type of platform.
Start off by opening up your “wp-config.php” file in any type of text editor. Just after the PHP opening tag, put the following two lines of code.
error_reporting(0); @ini_set('display_errors', 0);
The first line will tell PHP the level of error_reporting you want to set. Have a look at the PHP error_reporting manual for more details and information n the different levels you are able to set.
The second line executes the ini_set function which modifies the PHP configuration value “display_errors” and sets it to 0 (which turns it off). “display_errors” tells PHP whether or not errors should be displayed on the page. You can set it to 1 to display all errors. The reason for the “@” sign before the ini_set function is to silence a warning on the function. On some servers, especially shared hosting accounts, the PHP configuration cannot be modified unfortunately. It depends on your hosting account and provider.
And that’s it. All PHP errors, warnings and notices should now be hidden on your WordPress website. Remember to check for errors, warnings and notices on a development installation. You can then set error_reporting to E_ALL to display all errors.