Skip to content

Commit d431443

Browse files
committed
fix: log the vendor spl_object_hash() deprecation on PHP 8.6 instead of throwing
1 parent e3bf470 commit d431443

3 files changed

Lines changed: 86 additions & 37 deletions

File tree

‎docs/changelogs/v4.8.0.md‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ Release Date: Unreleased
6565

6666
- **CLI:** The `Console::run()` method now accepts an optional `array $tokens` parameter. This allows you to pass an array of command tokens directly to the console runner, which is useful for testing or programmatically running commands. If not provided, it will default to using the global `$argv`.
6767

68-
- **CodeIgniter:** The deprecated parameters in methods have been removed:
69-
- `CodeIgniter\CodeIgniter::handleRequest()` no longer accepts the deprecated `$cacheConfig` and `$returnResponse` parameters.
68+
- **CodeIgniter:** The deprecated parameters in methods have been removed:
69+
- `CodeIgniter\CodeIgniter::handleRequest()` no longer accepts the deprecated `$cacheConfig` and `$returnResponse` parameters.
7070
- `$cacheConfig` is no longer used and is now hard deprecated. A deprecation notice will be triggered if this is passed to the method.
7171
- `$returnResponse` has been removed, since it was already deprecated and unused.
7272
- The updated method signature is now `handleRequest(?RouteCollectionInterface $routes, ?Cache $cacheConfig = null)`.
@@ -75,7 +75,7 @@ Release Date: Unreleased
7575

7676
- **Config:** `CodeIgniter\Config\Services::request()` no longer accepts any parameter.
7777

78-
- **Database:** The following methods have had their signatures updated to remove deprecated parameters:
78+
- **Database:** The following methods have had their signatures updated to remove deprecated parameters:
7979
- `CodeIgniter\Database\Forge::_createTable()` no longer accepts the deprecated `$ifNotExists` parameter. The method signature is now `_createTable(string $table, array $attributes)`.
8080

8181
- **HTTP:** `CodeIgniter\HTTP\OutgoingRequest::__construct()` now requires the `$uri` parameter, which was previously `?URI $uri = null`. Passing `null` only worked when a `Host` header was supplied in the same call, since the constructor otherwise dereferences the URI to set that header. Consequently `OutgoingRequest::getUri()` now returns `URI` instead of `URI|null`, matching `OutgoingRequestInterface`. See [Upgrading from 4.7.x to 4.8.0](../installation/upgrade_480.md) for the migration.
@@ -86,41 +86,41 @@ Release Date: Unreleased
8686

8787
### Property Scope Changes
8888

89-
- **HTTP:** The following properties have changed their scope (visibility):
89+
- **HTTP:** The following properties have changed their scope (visibility):
9090
- `CodeIgniter\HTTP\RequestTrait::$ipAddress` is now private (previously protected).
9191

9292
### Method Scope Changes
9393

9494
- **CLI:** `CodeIgniter\CLI\Commands::getCommandAlternatives()` is now public (previously protected).
9595

96-
- **HTTP:** The following methods have changed their scope (visibility):
96+
- **HTTP:** The following methods have changed their scope (visibility):
9797
- `CodeIgniter\HTTP\URI::setUri()` is now private (previously public).
9898
- `CodeIgniter\HTTP\URI::refreshPath()` is now protected (previously public).
9999
- `CodeIgniter\HTTP\SiteURI::refreshPath()` is now protected (previously public).
100100

101101
### Removed Deprecated Items
102102

103-
- **Autoloader:** Removed the following deprecated methods:
103+
- **Autoloader:** Removed the following deprecated methods:
104104
- `CodeIgniter\Autoloader\Autoloader::sanitizeFileName()`
105105
- `CodeIgniter\Autoloader\Autoloader::discoverComposerNamespaces()`
106106

107107
- **Bootstrap:** The deprecated **system/bootstrap.php** file has been removed.
108108

109-
- **Cache:** Removed the following deprecated methods and constant:
109+
- **Cache:** Removed the following deprecated methods and constant:
110110
- `CodeIgniter\Cache\Handlers\BaseHandler::RESERVED_CHARACTERS` (deprecated since v4.1.5)
111111
- `CodeIgniter\Cache\Handlers\FileHandler::writeFile()` (deprecated since v4.6.0)
112112
- `CodeIgniter\Cache\Handlers\FileHandler::deleteFile()` (deprecated since v4.6.0)
113113
- `CodeIgniter\Cache\Handlers\FileHandler::getDirFileInfo()` (deprecated since v4.6.0)
114114
- `CodeIgniter\Cache\Handlers\FileHandler::getFileInfo()` (deprecated since v4.6.0)
115115

116-
- **CLI:** Removed the following deprecated properties and methods:
116+
- **CLI:** Removed the following deprecated properties and methods:
117117
- `CodeIgniter\CLI\BaseCommand::getPad()`
118118
- `CodeIgniter\CLI\CLI::$readline_support`
119119
- `CodeIgniter\CLI\CLI::$wait_msg`
120120
- `CodeIgniter\CLI\CLI::isWindows()`
121121
- `CodeIgniter\CLI\GeneratorTrait::execute()`
122122

123-
- **CodeIgniter:** Removed the following deprecated properties and methods:
123+
- **CodeIgniter:** Removed the following deprecated properties and methods:
124124
- `CodeIgniter\CodeIgniter::$cacheTTL`
125125
- `CodeIgniter\CodeIgniter::$returnResponse`
126126
- `CodeIgniter\CodeIgniter::initializeKint()`
@@ -136,10 +136,10 @@ Release Date: Unreleased
136136
- `CodeIgniter\CodeIgniter::callExit()`
137137
- `CodeIgniter\Test\MockCodeIgniter::callExit()`
138138

139-
- **Config:** Removed the following deprecated property:
139+
- **Config:** Removed the following deprecated property:
140140
- `CodeIgniter\Config\BaseService::$services` (deprecated since v4.5.0)
141141

142-
- **Database:** Removed the following deprecated properties and methods:
142+
- **Database:** Removed the following deprecated properties and methods:
143143
- `CodeIgniter\Database\BaseBuilder::setInsertBatch()`
144144
- `CodeIgniter\Database\BaseBuilder::setUpdateBatch()`
145145
- `CodeIgniter\Database\BaseBuilder::cleanClone()`
@@ -151,7 +151,7 @@ Release Date: Unreleased
151151
- `CodeIgniter\Database\OCI8\Forge::getError()`
152152
- `CodeIgniter\Database\SQLSRV\Forge::$createTableIfStr`
153153

154-
- **Debug:** Removed the following deprecated properties and methods:
154+
- **Debug:** Removed the following deprecated properties and methods:
155155
- `CodeIgniter\Debug\Toolbar\Collectors\BaseCollector::cleanPath()` (deprecated since v4.2.0)
156156
- `CodeIgniter\Debug\Exceptions::$ob_level` (deprecated since v4.4.0)
157157
- `CodeIgniter\Debug\Exceptions::$viewPath` (deprecated since v4.4.0)
@@ -164,25 +164,25 @@ Release Date: Unreleased
164164
- `CodeIgniter\Debug\Exceptions::describeMemory()` (deprecated since v4.4.0)
165165
- `CodeIgniter\Debug\Exceptions::highlightFile()` (deprecated since v4.4.0)
166166

167-
- **Exceptions:** Removed the following static constructors of `FrameworkException` and its child classes:
167+
- **Exceptions:** Removed the following static constructors of `FrameworkException` and its child classes:
168168
- `CodeIgniter\Exceptions\DownloadException::forCannotSetCache()`
169169
- `CodeIgniter\Exceptions\FrameworkException::forMissingExtension()`
170170
- `CodeIgniter\Honeypot\Exceptions\HoneypotException::forNoHiddenValue()`
171171
- `CodeIgniter\HTTP\Exceptions\HTTPException::forInvalidSameSiteSetting()`
172172
- `CodeIgniter\Security\Exceptions\SecurityException::forInvalidSameSite()`
173173
- `CodeIgniter\Session\Exceptions\SessionException::forInvalidSameSiteSetting()`
174174

175-
- **Files:** Removed the following deprecated method:
175+
- **Files:** Removed the following deprecated method:
176176
- `CodeIgniter\Files\File::getSizeByUnit()` (deprecated since v4.6.0)
177177

178-
- **Filters:** Removed the following deprecated properties and methods:
178+
- **Filters:** Removed the following deprecated properties and methods:
179179
- `CodeIgniter\Filters\Filters::$arguments` (deprecated since v4.6.0)
180180
- `CodeIgniter\Filters\Filters::$argumentsClass` (deprecated since v4.6.0)
181181
- `CodeIgniter\Filters\Filters::getArguments()` (deprecated since v4.6.0)
182182
- `CodeIgniter\Filters\Filters::discoverFilters()` and the auto-discovery of **Config/Filters.php** files (deprecated since v4.4.2)
183183
- `CodeIgniter\Filters\Filters::$modules` and the `$modules` constructor parameter, which were only used by the auto-discovery
184184

185-
- **HTTP:** Removed the following deprecated properties and methods:
185+
- **HTTP:** Removed the following deprecated properties and methods:
186186
- `CodeIgniter\HTTP\Message::getHeaders()` (deprecated since v4.0.5)
187187
- `CodeIgniter\HTTP\Message::getHeader()` (deprecated since v4.0.5)
188188
- `CodeIgniter\HTTP\RequestTrait::getEnv()` (deprecated since v4.4.4)
@@ -195,7 +195,7 @@ Release Date: Unreleased
195195
- `CodeIgniter\HTTP\SiteURI::setBaseURL()` (deprecated since v4.4.0)
196196
- `CodeIgniter\HTTP\SiteURI::setURI()` (deprecated since v4.4.0)
197197

198-
- **Security:** Removed the following deprecated properties and methods:
198+
- **Security:** Removed the following deprecated properties and methods:
199199
- `CodeIgniter\Security\SecurityInterface::sanitizeFilename()` (deprecated since v4.6.2)
200200
- `CodeIgniter\Security\Security::sanitizeFilename()` (deprecated since v4.6.2)
201201
- `CodeIgniter\Security\Security::$csrfProtection` (deprecated since v4.4.0)
@@ -356,15 +356,15 @@ Release Date: Unreleased
356356

357357
## Message Changes
358358

359-
- Added new language keys:
359+
- Added new language keys:
360360
- `Cache.unsupportedLockStore` (`CacheException::forUnsupportedLockStore()`)
361361
- `CLI.commandAlias` and `CLI.helpAliases` (command alias rendering in `list` and `help`)
362362
- `CLI.altCommandNone`, `CLI.altCommandRun`, and `CLI.altCommandSelect` (correcting a mistyped command)
363363
- `CLI.generator.invalidCommandType` (`make:command` rejecting an invalid `--type`)
364364
- `CLI.generator.invalidReturnType` (`make:model` rejecting an invalid `--return`)
365365
- `Commands.invalidCommandAlias`, `Commands.commandAliasSameAsName`, `Commands.duplicateCommandAlias`, `Commands.aliasClashesWithCommandName`, and `Commands.aliasClashesWithAlias` (command alias validation)
366366

367-
- Removed deprecated language keys tied to removed exception constructors:
367+
- Removed deprecated language keys tied to removed exception constructors:
368368
- `Core.missingExtension` (`FrameworkException::forMissingExtension()`)
369369
- `HTTP.cannotSetCache` (`DownloadException::forCannotSetCache()`)
370370
- `HTTP.disallowedAction`
@@ -375,6 +375,7 @@ Release Date: Unreleased
375375
## Changes
376376

377377
- **Config:** Added the `md` key for `Config\Mimes::$mimes` for Markdown files.
378+
- **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.
378379
- **Router:** Reduced route registration overhead in `RouteCollection::create()` by skipping placeholder replacement for route keys without `:` and calling `helper('array')` only once per collection.
379380

380381
## Deprecations
@@ -394,5 +395,6 @@ Release Date: Unreleased
394395
## Bugs Fixed
395396

396397
- **Config:** Fixed a bug where instantiating an anonymous `BaseConfig` subclass threw a `ValueError` from `getenv()` on PHP 8.6.
398+
- **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.
397399

398400
See the repo's [CHANGELOG.md](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md) for a complete list of bugs fixed.

‎system/Debug/Exceptions.php‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use CodeIgniter\HTTP\ResponseInterface;
2222
use Config\Exceptions as ExceptionsConfig;
2323
use ErrorException;
24-
use Psr\Log\LogLevel;
2524
use Throwable;
2625

2726
/**
@@ -141,8 +140,8 @@ public function resetForWorkerMode(): void
141140
public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null)
142141
{
143142
if ($this->isDeprecationError($severity)) {
144-
if ($this->isSessionSidDeprecationError($message, $file, $line)) {
145-
return true;
143+
if ($this->isSessionSidDeprecationError($message) || $this->isSplObjectHashDeprecationError($message, $file)) {
144+
return $this->handleDeprecationError($message, $file, $line);
146145
}
147146

148147
if (! $this->config->logDeprecations || (bool) env('CODEIGNITER_SCREAM_DEPRECATIONS')) {
@@ -188,25 +187,28 @@ public function shutdownHandler()
188187
}
189188

190189
/**
191-
* Handles session.sid_length and session.sid_bits_per_character deprecations in PHP 8.4.
190+
* Detects the `session.sid_length` and `session.sid_bits_per_character` deprecations in PHP 8.4.
192191
*/
193-
private function isSessionSidDeprecationError(string $message, ?string $file = null, ?int $line = null): bool
192+
private function isSessionSidDeprecationError(string $message): bool
194193
{
195-
if (PHP_VERSION_ID >= 80400 && str_contains($message, 'session.sid_')) {
196-
log_message(
197-
LogLevel::WARNING,
198-
'[DEPRECATED] {message} in {errFile} on line {errLine}.',
199-
[
200-
'message' => $message,
201-
'errFile' => clean_path($file ?? ''),
202-
'errLine' => $line ?? 0,
203-
],
204-
);
205-
206-
return true;
194+
return PHP_VERSION_ID >= 80400 && str_contains($message, 'session.sid_');
195+
}
196+
197+
/**
198+
* Detects the `spl_object_hash()` deprecation in PHP 8.6 raised by `mikey179/vfsstream` and `kint-php/kint`.
199+
*/
200+
private function isSplObjectHashDeprecationError(string $message, ?string $file = null): bool
201+
{
202+
if (! str_contains($message, 'spl_object_hash()')) {
203+
return false;
207204
}
208205

209-
return false;
206+
$file = str_replace('\\', '/', $file ?? '');
207+
208+
return str_contains($file, '/mikey179/vfsstream/')
209+
// @todo 4.8.0 Remove these checks once Kint v7 is released
210+
|| str_contains($file, '/kint-php/kint/')
211+
|| str_contains($file, '/system/ThirdParty/Kint/');
210212
}
211213

212214
/**

‎tests/system/Debug/ExceptionsTest.php‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Config\Exceptions as ExceptionsConfig;
2222
use ErrorException;
2323
use Override;
24+
use PHPUnit\Framework\Attributes\DataProvider;
2425
use PHPUnit\Framework\Attributes\Group;
2526

2627
/**
@@ -78,6 +79,50 @@ public function testDeprecationsOnPhp81DoNotThrow(): void
7879
}
7980
}
8081

82+
#[DataProvider('provideVendorSplObjectHashDeprecationDoesNotThrow')]
83+
public function testVendorSplObjectHashDeprecationDoesNotThrow(string $file): void
84+
{
85+
$config = new ExceptionsConfig();
86+
87+
$config->logDeprecations = false;
88+
$config->deprecationLogLevel = 'error';
89+
90+
$this->exception = new Exceptions($config);
91+
92+
$message = 'Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead';
93+
94+
$this->assertTrue($this->exception->errorHandler(E_DEPRECATED, $message, $file, 374));
95+
$this->assertLogContains('error', '[DEPRECATED] ' . $message);
96+
}
97+
98+
/**
99+
* @return iterable<string, array{string}>
100+
*/
101+
public static function provideVendorSplObjectHashDeprecationDoesNotThrow(): iterable
102+
{
103+
yield 'vfsStream' => [VENDORPATH . 'mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStreamFile.php'];
104+
105+
yield 'Kint via Composer' => [VENDORPATH . 'kint-php/kint/src/Parser/Parser.php'];
106+
107+
yield 'Kint via bundle' => [SYSTEMPATH . 'ThirdParty/Kint/Parser/Parser.php'];
108+
}
109+
110+
public function testSplObjectHashDeprecationOutsideVendorStillThrows(): void
111+
{
112+
$config = new ExceptionsConfig();
113+
114+
$config->logDeprecations = false;
115+
116+
$this->exception = new Exceptions($config);
117+
118+
$message = 'Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead';
119+
120+
$this->expectException(ErrorException::class);
121+
$this->expectExceptionMessage($message);
122+
123+
$this->exception->errorHandler(E_DEPRECATED, $message, APPPATH . 'Foo.php', 1);
124+
}
125+
81126
public function testSuppressedDeprecationsAreLogged(): void
82127
{
83128
$config = new ExceptionsConfig();

0 commit comments

Comments
 (0)