Skip to content

Commit

Permalink
Merge pull request #9140 from kenjis/workaround-for-implicit-nullable…
Browse files Browse the repository at this point in the history
…-deprecations

[4.6] feat: workaround for implicit nullable deprecations in PHP 8.4
  • Loading branch information
kenjis authored Sep 6, 2024
2 parents 4a4a648 + 2eeb971 commit e570f46
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -253,6 +257,38 @@ 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"
*
* @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,
'[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.
Expand Down

0 comments on commit e570f46

Please sign in to comment.