Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: workaround for Faker deprecation errors in PHP 8.2 #6758

Merged
merged 3 commits into from
Oct 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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