From 6c5938e81cf99a033b027b6155178f7ea53d63af Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sat, 21 Nov 2026 02:15:39 +0800 Subject: [PATCH] fix: log the vendor `spl_object_hash()` deprecation on PHP 8.6 instead of throwing --- docs/changelogs/v4.8.0.md | 2 ++ system/Debug/Exceptions.php | 38 +++++++++++----------- tests/system/Debug/ExceptionsTest.php | 45 +++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/docs/changelogs/v4.8.0.md b/docs/changelogs/v4.8.0.md index a45cb9afaeda..e397ab146b2f 100644 --- a/docs/changelogs/v4.8.0.md +++ b/docs/changelogs/v4.8.0.md @@ -375,6 +375,7 @@ Release Date: Unreleased ## Changes - **Config:** Added the `md` key for `Config\Mimes::$mimes` for Markdown files. +- **Debug:** The PHP 8.4 `session.sid_length` and `session.sid_bits_per_character` deprecations are now logged at `Config\Exceptions::$deprecationLogLevel` with a backtrace, instead of at the `warning` level without one. - **Router:** Reduced route registration overhead in `RouteCollection::create()` by skipping placeholder replacement for route keys without `:` and calling `helper('array')` only once per collection. ## Deprecations @@ -394,6 +395,7 @@ Release Date: Unreleased ## Bugs Fixed - **Config:** Fixed a bug where instantiating an anonymous `BaseConfig` subclass threw a `ValueError` from `getenv()` on PHP 8.6. +- **Debug:** Fixed a bug where the `spl_object_hash()` deprecation raised by `mikey179/vfsstream` and `kint-php/kint` on PHP 8.6 was thrown as an exception. It is now logged as a deprecation. - **Testing:** Fixed a bug where `ReflectionHelper::getPrivateMethodInvoker()` passed an object when invoking a static method, which is deprecated in PHP 8.6. See the repo's [CHANGELOG.md](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md) for a complete list of bugs fixed. diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 7cdf4f1959da..72151988148d 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -21,7 +21,6 @@ use CodeIgniter\HTTP\ResponseInterface; use Config\Exceptions as ExceptionsConfig; use ErrorException; -use Psr\Log\LogLevel; use Throwable; /** @@ -141,8 +140,8 @@ public function resetForWorkerMode(): void 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->isSessionSidDeprecationError($message) || $this->isSplObjectHashDeprecationError($message, $file)) { + return $this->handleDeprecationError($message, $file, $line); } if (! $this->config->logDeprecations || (bool) env('CODEIGNITER_SCREAM_DEPRECATIONS')) { @@ -188,25 +187,28 @@ public function shutdownHandler() } /** - * Handles session.sid_length and session.sid_bits_per_character deprecations in PHP 8.4. + * Detects the `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 + private function isSessionSidDeprecationError(string $message): 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 PHP_VERSION_ID >= 80400 && str_contains($message, 'session.sid_'); + } + + /** + * Detects the `spl_object_hash()` deprecation in PHP 8.6 raised by `mikey179/vfsstream` and `kint-php/kint`. + */ + private function isSplObjectHashDeprecationError(string $message, ?string $file = null): bool + { + if (! str_contains($message, 'spl_object_hash()')) { + return false; } - return false; + $file = str_replace('\\', '/', $file ?? ''); + + return str_contains($file, '/mikey179/vfsstream/') + // @todo 4.8.0 Remove these checks once Kint v7 is released + || str_contains($file, '/kint-php/kint/') + || str_contains($file, '/system/ThirdParty/Kint/'); } /** diff --git a/tests/system/Debug/ExceptionsTest.php b/tests/system/Debug/ExceptionsTest.php index 515cd49879ea..ed58a8b1e8e6 100644 --- a/tests/system/Debug/ExceptionsTest.php +++ b/tests/system/Debug/ExceptionsTest.php @@ -21,6 +21,7 @@ use Config\Exceptions as ExceptionsConfig; use ErrorException; use Override; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; /** @@ -78,6 +79,50 @@ public function testDeprecationsOnPhp81DoNotThrow(): void } } + #[DataProvider('provideVendorSplObjectHashDeprecationDoesNotThrow')] + public function testVendorSplObjectHashDeprecationDoesNotThrow(string $file): void + { + $config = new ExceptionsConfig(); + + $config->logDeprecations = false; + $config->deprecationLogLevel = 'error'; + + $this->exception = new Exceptions($config); + + $message = 'Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead'; + + $this->assertTrue($this->exception->errorHandler(E_DEPRECATED, $message, $file, 374)); + $this->assertLogContains('error', '[DEPRECATED] ' . $message); + } + + /** + * @return iterable + */ + public static function provideVendorSplObjectHashDeprecationDoesNotThrow(): iterable + { + yield 'vfsStream' => [VENDORPATH . 'mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStreamFile.php']; + + yield 'Kint via Composer' => [VENDORPATH . 'kint-php/kint/src/Parser/Parser.php']; + + yield 'Kint via bundle' => [SYSTEMPATH . 'ThirdParty/Kint/Parser/Parser.php']; + } + + public function testSplObjectHashDeprecationOutsideVendorStillThrows(): void + { + $config = new ExceptionsConfig(); + + $config->logDeprecations = false; + + $this->exception = new Exceptions($config); + + $message = 'Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead'; + + $this->expectException(ErrorException::class); + $this->expectExceptionMessage($message); + + $this->exception->errorHandler(E_DEPRECATED, $message, APPPATH . 'Foo.php', 1); + } + public function testSuppressedDeprecationsAreLogged(): void { $config = new ExceptionsConfig();