5

I'm still getting a lot of PHP Deprecation and Notice messages in my logs despite having these values turned off in php.ini. According to admin/config/development/logging I should only be displaying errors and warning if that is relevant. Is there some other way that Drupal might override my php.ini settings?

3
  • 2
    Have you restarted your server?
    – Sithu
    Nov 29, 2012 at 11:21
  • For the record, the real solution is not to disable error logging, but to fix file bugs/fix the errors. Errors should be logged. (But not displayed in a production environment)
    – Letharion
    Nov 29, 2012 at 16:54
  • I agree, but on production the mass of notices and deprecation errors really gets in the way of trying to find legitimate issues.
    – DanH
    Nov 30, 2012 at 4:03

1 Answer 1

6

In drupal_environment_initialize(), Drupal changes the report level with the following code.

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

The value of E_ALL changes basing on the PHP version, and it is:

--------------------------------------------------------------------------------
PHP   | Value expressed using the other constants                              |
-------------------------------------------------------------------------------|
Before| E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING         |
5.2.x | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING    |
      | E_USER_NOTICE                                                          | 
-------------------------------------------------------------------------------|
5.2.x | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING         |
      | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING    |
      | E_USER_NOTICE | E_RECOVERABLE_ERROR                                    | 
-------------------------------------------------------------------------------|
5.3.x | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING         |
      | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING    |
      | E_USER_NOTICE | E_RECOVERABLE_ERROR | E_DEPRECATED | E_USER_DEPRECATED | 
-------------------------------------------------------------------------------|
5.4.x | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING         |
      | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING    |
      | E_USER_NOTICE | E_STRICT | E_RECOVERABLE_ERROR | E_DEPRECATED          |
      | E_USER_DEPRECATED                                                      | 
--------------------------------------------------------------------------------

With all the PHP versions, error_reporting(E_ALL | error_reporting()) causes any warning to be raised; since PHP 5.3, it causes any deprecation message to be raised too.

drupal_environment_initialize() is the only place where Drupal sets the error level. A custom settings.php file could change it with ini_set('error_reporting'). Since settings.php is included after drupal_environment_initialize() is executed, that file could restrict the error level, or expand it; this means that with PHP 5.3, settings.php could cause E_STRICT errors to be raised too.

function _drupal_bootstrap_configuration() {
  // Set the Drupal custom error handler.
  set_error_handler('_drupal_error_handler');
  set_exception_handler('_drupal_exception_handler');

  drupal_environment_initialize();
  // Start a page timer:
  timer_start('page');
  // Initialize the configuration, including variables from settings.php.
  drupal_settings_initialize();
}

About the error levels, the PHP documentation has the following notes:

In PHP 5 a new error level E_STRICT is available. Prior to PHP 5.4.0 E_STRICT was not included within E_ALL, so you would have to explicitly enable this kind of error level in PHP < 5.4.0. Enabling E_STRICT during development has some benefits. STRICT messages provide suggestions that can help ensure the best interoperability and forward compatibility of your code. These messages may include things such as calling non-static methods statically, defining properties in a compatible class definition while defined in a used trait, and prior to PHP 5.3 some deprecated features would issue E_STRICT errors such as assigning objects by reference upon instantiation.

If you are using PHP 5.4, that would explain why Drupal is recording E_STRICT errors, since Drupal adds E_ALL to the error level.

2
  • 2
    Added ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_NOTICE); to settings.php, problem solved, thanks! I assumed this probably would be the solution, however you explained the reasons why quite expertly :D
    – DanH
    Nov 30, 2012 at 4:22
  • 1
    I am sorry my previous answer was not so explicit; I realized that after I took a nap. I think my answer is much better now. :)
    – apaderno
    Nov 30, 2012 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.