function _drupal_error_handler_real
Same name in other branches
- 7.x includes/errors.inc \_drupal_error_handler_real()
- 8.9.x core/includes/errors.inc \_drupal_error_handler_real()
- 10 core/includes/errors.inc \_drupal_error_handler_real()
- 11.x core/includes/errors.inc \_drupal_error_handler_real()
Provides custom PHP error handling.
Parameters
$error_level: The level of the error raised.
$message: The error message.
$filename: The filename that the error was raised in.
$line: The line number the error was raised at.
1 call to _drupal_error_handler_real()
- _drupal_error_handler in core/
includes/ bootstrap.inc - Provides custom PHP error handling.
File
-
core/
includes/ errors.inc, line 58
Code
function _drupal_error_handler_real($error_level, $message, $filename, $line) {
if ($error_level & error_reporting()) {
$types = drupal_error_levels();
[
$severity_msg,
$severity_level,
] = $types[$error_level];
$backtrace = debug_backtrace();
$caller = Error::getLastCaller($backtrace);
// We treat recoverable errors as fatal.
$recoverable = $error_level == E_RECOVERABLE_ERROR;
// As __toString() methods must not throw exceptions (recoverable errors)
// in PHP, we allow them to trigger a fatal error by emitting a user error
// using trigger_error().
$to_string = $error_level == E_USER_ERROR && substr($caller['function'], -strlen('__toString()')) == '__toString()';
_drupal_log_error([
'%type' => isset($types[$error_level]) ? $severity_msg : 'Unknown error',
// The standard PHP error handler considers that the error messages
// are HTML. We mimic this behavior here.
'@message' => Markup::create(Xss::filterAdmin($message)),
'%function' => $caller['function'],
'%file' => $caller['file'],
'%line' => $caller['line'],
'severity_level' => $severity_level,
'backtrace' => $backtrace,
'@backtrace_string' => (new \Exception())->getTraceAsString(),
'exception' => NULL,
], $recoverable || $to_string);
}
elseif (DRUPAL_TEST_IN_CHILD_SITE && $error_level === E_USER_DEPRECATED) {
static $seen = [];
if (array_search($message, $seen, TRUE) === FALSE) {
// Only report each deprecation once. Too many headers can break some
// Chrome and web driver testing.
$seen[] = $message;
$backtrace = debug_backtrace();
$caller = Error::getLastCaller($backtrace);
_drupal_error_header(Markup::create(Xss::filterAdmin($message)), 'User deprecated function', $caller['function'], $caller['file'], $caller['line']);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.