function drupal_error_handler
6.x common.inc | drupal_error_handler($errno, $message, $filename, $line, $context) |
Log errors as defined by administrator.
Error levels:
- 0 = Log errors to database.
- 1 = Log errors to database and to screen.
1 string reference to 'drupal_error_handler'
- _drupal_bootstrap_full in drupal-6.x/
includes/ common.inc
File
- drupal-6.x/
includes/ common.inc, line 661 - Common functions that many Drupal modules will need to reference.
Code
function drupal_error_handler($errno, $message, $filename, $line, $context) {
// If the @ error suppression operator was used, error_reporting will have
// been temporarily set to 0.
if (error_reporting() == 0) {
return;
}
if ($errno & (E_ALL ^ E_DEPRECATED)) {
$types = array(1 => 'error', 2 => 'warning', 4 => 'parse error', 8 => 'notice', 16 => 'core error', 32 => 'core warning', 64 => 'compile error', 128 => 'compile warning', 256 => 'user error', 512 => 'user warning', 1024 => 'user notice', 2048 => 'strict warning', 4096 => 'recoverable fatal error');
// For database errors, we want the line number/file name of the place that
// the query was originally called, not _db_query().
if (isset($context[DB_ERROR])) {
$backtrace = array_reverse(debug_backtrace());
// List of functions where SQL queries can originate.
$query_functions = array('db_query', 'pager_query', 'db_query_range', 'db_query_temporary', 'update_sql');
// Determine where query function was called, and adjust line/file
// accordingly.
foreach ($backtrace as $index => $function) {
if (in_array($function['function'], $query_functions)) {
$line = $backtrace[$index]['line'];
$filename = $backtrace[$index]['file'];
break;
}
}
}
// Try to use filter_xss(). If it's too early in the bootstrap process for
// filter_xss() to be loaded, use check_plain() instead.
$entry = check_plain($types[$errno]) . ': ' . (function_exists('filter_xss') ? filter_xss($message) : check_plain($message)) . ' in ' . check_plain($filename) . ' on line ' . check_plain($line) . '.';
// Force display of error messages in update.php.
if (variable_get('error_level', 1) == 1 || strstr($_SERVER['SCRIPT_NAME'], 'update.php')) {
drupal_set_message($entry, 'error');
}
watchdog('php', '%message in %file on line %line.', array('%error' => $types[$errno], '%message' => $message, '%file' => $filename, '%line' => $line), WATCHDOG_ERROR);
}
}