function _drupal_error_header

Same name in other branches
  1. 8.9.x core/includes/errors.inc \_drupal_error_header()
  2. 10 core/includes/errors.inc \_drupal_error_header()
  3. 11.x core/includes/errors.inc \_drupal_error_header()

Adds error information to headers so that tests can access it.

Parameters

$message: The error message.

$type: The type of error.

$function: The function that emitted the error.

$file: The file that emitted the error.

$line: The line number in file that emitted the error.

2 calls to _drupal_error_header()
_drupal_error_handler_real in core/includes/errors.inc
Provides custom PHP error handling.
_drupal_log_error in core/includes/errors.inc
Logs a PHP error or exception and displays an error page in fatal cases.

File

core/includes/errors.inc, line 349

Code

function _drupal_error_header($message, $type, $function, $file, $line) {
    // $number does not use drupal_static as it should not be reset
    // as it uniquely identifies each PHP error.
    static $number = 0;
    $assertion = [
        $message,
        $type,
        [
            'function' => $function,
            'file' => $file,
            'line' => $line,
        ],
    ];
    // For non-fatal errors (e.g. PHP notices) _drupal_log_error can be called
    // multiple times per request. In that case the response is typically
    // generated outside of the error handler, e.g., in a controller. As a
    // result it is not possible to use a Response object here but instead the
    // headers need to be emitted directly.
    header('X-Drupal-Assertion-' . $number . ': ' . rawurlencode(serialize($assertion)));
    $number++;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.