How do I silence PHP errors?

Solutions

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

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

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: Drupal 7

Similar questions

Using drupal_add_feed() in template.php gives warning errors
As soon as I add a call to drupal_add_feed in my theme template.php file I get this warning: Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in theme_get_registry() (line 277 of /var/www/example.com/includes/theme.inc). The feed (created by Views) is valid, and the code works, i.e. it does add th...
Watchdog errors with location = http://default/index.php
Looking through recent log messages, I've got a number of errors with no referrer listed, and showing location as being http://default/index.php (instead of http://mysite.com/some/page). They all seem to be triggered by "Anonymous" from localhost (127.0.0.1). Example screenshots are below. Anyone know what kind of sense I should make of these entri...
Getting WSOD, can't view any errors even after editing index.php
I've tried entering: at the beginning of my index.php file (after begin php tag and it hasn't done anything. When I run cron, it comes back and tells me that everything is ok. Here's a brief overview of things that have transpired today: I cleared cache, went back and tried to replace my .htdocs files with something more simplistic and still no go....
Write all PHP errors, warnings and notices to error_log
Drupal catches PHP warnings and notices to log them via dblog or syslog. As a result, there are two places to monitor for PHP errors (with the watchdog UI not well suited to cater for any large number of notices). Is it possible to prevent this behavior and have ALL php errors be logged to the error_log defined in the php config?
cron.php failing with errors
I have a site running Drupal 6.30 which has started giving errors when it run the hourly call to cron.php. The cronjob in question is and run as root: I get the following rather cryptic / truncated message when it runs I have looked in system logs and apache logs but do not see anything that would indicate reason for the problem. Would anyone be ab...
Is there a module or configuration that logs PHP mail errors?
On shared hosting. We're having strange mail problems... mails do not get sent to various domains or are delayed. It seems to happen more in Webforms than in Notify_message actions in Rules. Is there a way to log the PHP mail() error messages without hacking the MimeMail module? The Drupal log only shows that there was an error... nothing more spec...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.