Skip to content

Commit

Permalink
Merge pull request #6758 from kenjis/fix-Faker-php82-deprecation
Browse files Browse the repository at this point in the history
fix: workaround for Faker deprecation errors in PHP 8.2
  • Loading branch information
kenjis authored Oct 27, 2022
2 parents 30258d5 + e8c09a5 commit 89c8a6c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Config\Exceptions as ExceptionsConfig;
use Config\Paths;
use ErrorException;
use Psr\Log\LogLevel;
use Throwable;

/**
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 89c8a6c

Please sign in to comment.