From 02341c39259d9864badf67b22f050e81d7c5ff46 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 26 Oct 2022 09:24:04 +0900 Subject: [PATCH 1/3] fix: workaround for Faker deprecation errors in PHP 8.2. --- system/Debug/Exceptions.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 8c8ff25d28d4..91621483f896 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -152,6 +152,18 @@ public function exceptionHandler(Throwable $exception) public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null) { if (error_reporting() & $severity) { + // Workaround for Faker deprecation errors in PHP 8.2. + // See https://github.com/FakerPHP/Faker/issues/479 + // @TODO Remove if Faker is fixed. + if ( + $severity === E_DEPRECATED + && strpos($file, VENDORPATH . 'fakerphp/faker/') !== false + && $message === 'Use of "static" in callables is deprecated' + ) { + // Ignore the error. + return true; + } + throw new ErrorException($message, 0, $severity, $file, $line); } From 7bd1ed524ebaa6ad81176bbf32378e7d6729dc32 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Oct 2022 09:13:48 +0900 Subject: [PATCH 2/3] feat: add logging --- system/Debug/Exceptions.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 91621483f896..df30b76c3657 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; /** @@ -160,6 +161,16 @@ public function errorHandler(int $severity, string $message, ?string $file = nul && 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, + ] + ); + // Ignore the error. return true; } From e8c09a599da67e1decb9c891b89d91795609f6fd Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 27 Oct 2022 09:32:58 +0900 Subject: [PATCH 3/3] refactor: extract method --- system/Debug/Exceptions.php | 46 +++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index df30b76c3657..f550c71c785a 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -153,24 +153,8 @@ public function exceptionHandler(Throwable $exception) public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null) { if (error_reporting() & $severity) { - // Workaround for Faker deprecation errors in PHP 8.2. - // See https://github.com/FakerPHP/Faker/issues/479 // @TODO Remove if Faker is fixed. - 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, - ] - ); - + if ($this->isFakerDeprecationError($severity, $message, $file, $line)) { // Ignore the error. return true; } @@ -181,6 +165,34 @@ public function errorHandler(int $severity, string $message, ?string $file = nul 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.