diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 8c8ff25d28d4..f550c71c785a 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -20,6 +20,7 @@ use Config\Exceptions as ExceptionsConfig; use Config\Paths; use ErrorException; +use Psr\Log\LogLevel; use Throwable; /** @@ -152,12 +153,46 @@ public function exceptionHandler(Throwable $exception) public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null) { if (error_reporting() & $severity) { + // @TODO Remove if Faker is fixed. + if ($this->isFakerDeprecationError($severity, $message, $file, $line)) { + // Ignore the error. + return true; + } + throw new ErrorException($message, 0, $severity, $file, $line); } return false; // return false to propagate the error to PHP standard error handler } + /** + * Workaround for Faker deprecation errors in PHP 8.2. + * + * @see https://github.com/FakerPHP/Faker/issues/479 + */ + private function isFakerDeprecationError(int $severity, string $message, ?string $file = null, ?int $line = null) + { + if ( + $severity === E_DEPRECATED + && strpos($file, VENDORPATH . 'fakerphp/faker/') !== false + && $message === 'Use of "static" in callables is deprecated' + ) { + log_message( + LogLevel::WARNING, + '[DEPRECATED] {message} in {errFile} on line {errLine}.', + [ + 'message' => $message, + 'errFile' => clean_path($file ?? ''), + 'errLine' => $line ?? 0, + ] + ); + + return true; + } + + return false; + } + /** * Checks to see if any errors have happened during shutdown that * need to be caught and handle them.