Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelogs/v4.8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
38 changes: 20 additions & 18 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use CodeIgniter\HTTP\ResponseInterface;
use Config\Exceptions as ExceptionsConfig;
use ErrorException;
use Psr\Log\LogLevel;
use Throwable;

/**
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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/');
}

/**
Expand Down
45 changes: 45 additions & 0 deletions tests/system/Debug/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Config\Exceptions as ExceptionsConfig;
use ErrorException;
use Override;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

/**
Expand Down Expand Up @@ -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<string, array{string}>
*/
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();
Expand Down
Loading