From ba1702f147a86f2b2694ae5fa7981a0854234e1c Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 22 Aug 2024 10:55:32 +0900 Subject: [PATCH 1/2] feat: add workround for implicit nullable deprecation errors in PHP 8.4 --- system/Debug/Exceptions.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index fac10b32114d..a88ccc550ae0 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -213,6 +213,10 @@ public function errorHandler(int $severity, string $message, ?string $file = nul return true; } + if ($this->isImplicitNullableDeprecationError($message, $file, $line)) { + return true; + } + if (! $this->config->logDeprecations || (bool) env('CODEIGNITER_SCREAM_DEPRECATIONS')) { throw new ErrorException($message, 0, $severity, $file, $line); } @@ -253,6 +257,34 @@ private function isSessionSidDeprecationError(string $message, ?string $file = n return false; } + /** + * Workaround to implicit nullable deprecation errors in PHP 8.4. + * + * "Implicitly marking parameter $xxx as nullable is deprecated, + * the explicit nullable type must be used instead" + */ + private function isImplicitNullableDeprecationError(string $message, ?string $file = null, ?int $line = null): bool + { + if ( + PHP_VERSION_ID >= 80400 + && str_contains($message, 'the explicit nullable type must be used instead') + ) { + 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. From 2eeb9717700a9df07f4446c140d1d63628be5eb0 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 6 Sep 2024 08:57:38 +0900 Subject: [PATCH 2/2] fix: only Faker/Kint errors are skipped This is a workaround for the dependent packages that are not compatible with PHP 8.4. So we should not skip all implicit nullable deprecations. --- system/Debug/Exceptions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index a88ccc550ae0..2c88bf695985 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -262,12 +262,16 @@ private function isSessionSidDeprecationError(string $message, ?string $file = n * * "Implicitly marking parameter $xxx as nullable is deprecated, * the explicit nullable type must be used instead" + * + * @TODO remove this before v4.6.0 release */ private function isImplicitNullableDeprecationError(string $message, ?string $file = null, ?int $line = null): bool { if ( PHP_VERSION_ID >= 80400 && str_contains($message, 'the explicit nullable type must be used instead') + // Only Kint and Faker, which cause this error, are logged. + && (str_starts_with($message, 'Kint\\') || str_starts_with($message, 'Faker\\')) ) { log_message( LogLevel::WARNING,