Tag Archives: turn off php errors

Turn PHP Error Reporting On or Off

Sometimes it maybe convenient to enable or disable PHP error reporting from a script. Ultimately error reporting is contoroled from your server's php.ini configuration file for PHP. This is an alternative method for cases where you might not have access to php.ini. I also use it quite often for debugging scripts myself.

 

Turning Error Reporting Off

If you are getting errors showing up in your website, then you may want to turn error reporting off so users won't see any errors. To turn it off, add the following line of code to the very top of your PHP script:

error_reporting(0);

Turn On Error Reporting for PHP

To make sure error_reporting is on for testing and debugging a script, add the following line of code to the very top of your PHP script:

error_reporting(-1);

Then you can always just comment the line out when you are done testing.

 Force Error Reporting for PHP Script

If you find yourself using a server where you don't have access to php.ini and cannot view PHP errors, try adding this to the top of your file as well:

error_reporting(E_ALL);

ini_set('display_errors', '1');