diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index b21f6078eba..e0c1271599e 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1300,7 +1300,7 @@ function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG // It is possible that the error handling will itself trigger an error. In that case, we could // end up in an infinite loop. To avoid that, we implement a simple static semaphore. - if (!$in_error_state && function_exists('module_implements')) { + if (!$in_error_state && \Drupal::hasService('module_handler')) { $in_error_state = TRUE; // The user object may not exist in all conditions, so 0 is substituted if needed. diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 208a6791af9..37b875e7662 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -169,7 +169,7 @@ function _drupal_log_error($error, $fatal = FALSE) { } } - if (\Drupal::request()->isXmlHttpRequest()) { + if (\Drupal::hasRequest() && \Drupal::request()->isXmlHttpRequest()) { if ($fatal) { if (error_displayable($error)) { // When called from JavaScript, simply output the error message. diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index f07ea7fa577..61277380cce 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -149,6 +149,16 @@ class Drupal { return static::$container && static::$container->has($id); } + /** + * Indicates if there is a currently active request object. + * + * @return bool + * TRUE if there is a currently active request object, FALSE otherwise. + */ + public static function hasRequest() { + return static::$container && static::$container->has('request') && static::$container->initialized('request') && static::$container->isScopeActive('request'); + } + /** * Retrieves the currently active request object. *