You are here

function _drupal_trigger_error_with_delayed_logging in Drupal 7

Invokes trigger_error() with logging delayed until the end of the request.

This is an alternative to PHP's trigger_error() function which can be used during low-level Drupal core operations that need to avoid being interrupted by a watchdog() call.

Normally, Drupal's error handler calls watchdog() in response to a trigger_error() call. However, this invokes hook_watchdog() which can run arbitrary code. If the trigger_error() happens in the middle of an operation such as a rebuild operation which should not be interrupted by arbitrary code, that could potentially break or trigger the rebuild again. This function protects against that by delaying the watchdog() call until the end of the current page request.

This is an internal function which should only be called by low-level Drupal core functions. It may be removed in a future Drupal 7 release.

Parameters

string $error_msg: The error message to trigger. As with trigger_error() itself, this is limited to 1024 bytes; additional characters beyond that will be removed.

int $error_type: (optional) The type of error. This should be one of the E_USER family of constants. As with trigger_error() itself, this defaults to E_USER_NOTICE if not provided.

See also

_drupal_log_error()

2 calls to _drupal_trigger_error_with_delayed_logging()
DrupalRequestSanitizer::sanitize in includes/request-sanitizer.inc
Modifies the request to strip dangerous keys from user input.
_drupal_get_filename_fallback_trigger_error in includes/bootstrap.inc
Triggers a user-level warning for missing or unexpectedly moved files.
1 string reference to '_drupal_trigger_error_with_delayed_logging'
_drupal_log_error in includes/errors.inc
Logs a PHP error or exception and displays an error page in fatal cases.

File

includes/bootstrap.inc, line 1153
Functions that need to be loaded on every Drupal request.

Code

function _drupal_trigger_error_with_delayed_logging($error_msg, $error_type = E_USER_NOTICE) {
  $delay_logging =& drupal_static(__FUNCTION__, FALSE);
  $delay_logging = TRUE;
  trigger_error($error_msg, $error_type);
  $delay_logging = FALSE;
}