Skip to content

Commit 89c8a6c

Browse files
authored
Merge pull request #6758 from kenjis/fix-Faker-php82-deprecation
fix: workaround for Faker deprecation errors in PHP 8.2
2 parents 30258d5 + e8c09a5 commit 89c8a6c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

system/Debug/Exceptions.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Config\Exceptions as ExceptionsConfig;
2121
use Config\Paths;
2222
use ErrorException;
23+
use Psr\Log\LogLevel;
2324
use Throwable;
2425

2526
/**
@@ -152,12 +153,46 @@ public function exceptionHandler(Throwable $exception)
152153
public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null)
153154
{
154155
if (error_reporting() & $severity) {
156+
// @TODO Remove if Faker is fixed.
157+
if ($this->isFakerDeprecationError($severity, $message, $file, $line)) {
158+
// Ignore the error.
159+
return true;
160+
}
161+
155162
throw new ErrorException($message, 0, $severity, $file, $line);
156163
}
157164

158165
return false; // return false to propagate the error to PHP standard error handler
159166
}
160167

168+
/**
169+
* Workaround for Faker deprecation errors in PHP 8.2.
170+
*
171+
* @see https://github.com/FakerPHP/Faker/issues/479
172+
*/
173+
private function isFakerDeprecationError(int $severity, string $message, ?string $file = null, ?int $line = null)
174+
{
175+
if (
176+
$severity === E_DEPRECATED
177+
&& strpos($file, VENDORPATH . 'fakerphp/faker/') !== false
178+
&& $message === 'Use of "static" in callables is deprecated'
179+
) {
180+
log_message(
181+
LogLevel::WARNING,
182+
'[DEPRECATED] {message} in {errFile} on line {errLine}.',
183+
[
184+
'message' => $message,
185+
'errFile' => clean_path($file ?? ''),
186+
'errLine' => $line ?? 0,
187+
]
188+
);
189+
190+
return true;
191+
}
192+
193+
return false;
194+
}
195+
161196
/**
162197
* Checks to see if any errors have happened during shutdown that
163198
* need to be caught and handle them.

0 commit comments

Comments
 (0)