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\ErrorHandlerCode
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();
}
}