Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ErrorHandler.php

function ErrorHandler::call

Calls a function and turns any PHP error into \ErrorException.

Throws

\ErrorException When $function(...$arguments) triggers a PHP error

File

vendor/symfony/error-handler/ErrorHandler.php, line 160

Class

ErrorHandler
A generic ErrorHandler for the PHP engine.

Namespace

Symfony\Component\ErrorHandler

Code

public static function call(callable $function, mixed ...$arguments) : mixed {
    set_error_handler(static function (int $type, string $message, string $file, int $line) {
        if (__FILE__ === $file) {
            $trace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 3);
            $file = $trace[2]['file'] ?? $file;
            $line = $trace[2]['line'] ?? $line;
        }
        throw new \ErrorException($message, 0, $type, $file, $line);
    });
    try {
        return $function(...$arguments);
    } finally {
        restore_error_handler();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal