Drupal - How do I silence PHP errors?

The path changes, as in Drupal 7 the same page you would before see at admin/settings/error-reporting is now at admin/config/development/logging.

screenshot


As suggested, in Administration » Configuration » Development (at /admin/config/development/logging) you can find the setting to disable displaying of error messages, but it won't disable error/notices completely.

It's because Drupal 7 enforces E_ALL, so they're still written to syslog and you can see them in Recent logs affecting your website performance.

To disable the notices completely, you'll have to add the following line into your settings.php or php.ini file:

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);

Show all errors, except for notices and coding standards warnings.

To silence all PHP errors, which is not recommended, you may try to addin your settings file:

error_reporting(0); // Disable all errors.

See: error_reporting()


Responsible Drupal 7 core code for E_ALL logging (file: includes/bootstrap.inc):

// Enforce E_ALL, but allow users to set levels not part of E_ALL.
error_reporting(E_ALL | error_reporting());

See also:

  • Enable users to determine which types of watchdog messages get written to syslog. at DO
  • Add filtering to dblog before log entries go in. at DO
  • Disabling PHP Deprecation Warnings and Notices at SF

One thing no one has mentioned that may be helpful for people to know is that Drupal 7 ignores all local system error reporting levels. So you can't use .htaccess or even php.ini to set php error reporting levels in Drupal.

There is a patch proposed for this in D8, but currently in D7 you're restricted to the 3 error masks –all, none, or errors & warnings– that are set on the admin page kiamlaluno indicated.

Tags:

7