From 10aebe2b933c6cbc19832a7a1f24e53e2e2e37a9 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Aug 2024 13:02:18 +0900 Subject: [PATCH] feat: add deprecation error handling for session.sid_length and session.sid_bits_per_character --- system/Debug/Exceptions.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index e5f7ecb04881..fac10b32114d 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -209,6 +209,10 @@ public function exceptionHandler(Throwable $exception) public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null) { if ($this->isDeprecationError($severity)) { + if ($this->isSessionSidDeprecationError($message, $file, $line)) { + return true; + } + if (! $this->config->logDeprecations || (bool) env('CODEIGNITER_SCREAM_DEPRECATIONS')) { throw new ErrorException($message, 0, $severity, $file, $line); } @@ -223,6 +227,32 @@ public function errorHandler(int $severity, string $message, ?string $file = nul return false; // return false to propagate the error to PHP standard error handler } + /** + * Handles session.sid_length and session.sid_bits_per_character deprecations + * in PHP 8.4. + */ + private function isSessionSidDeprecationError(string $message, ?string $file = null, ?int $line = null): bool + { + if ( + PHP_VERSION_ID >= 80400 + && str_contains($message, 'session.sid_') + ) { + 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.