Skip to content

Commit b483b9e

Browse files
committed
feat: add workround for implicit nullable deprecation errors in PHP 8.4
1 parent c9434c9 commit b483b9e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

system/Debug/Exceptions.php

+32
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ public function errorHandler(int $severity, string $message, ?string $file = nul
213213
return true;
214214
}
215215

216+
if ($this->isImplicitNullableDeprecationError($message, $file, $line)) {
217+
return true;
218+
}
219+
216220
if (! $this->config->logDeprecations || (bool) env('CODEIGNITER_SCREAM_DEPRECATIONS')) {
217221
throw new ErrorException($message, 0, $severity, $file, $line);
218222
}
@@ -253,6 +257,34 @@ private function isSessionSidDeprecationError(string $message, ?string $file = n
253257
return false;
254258
}
255259

260+
/**
261+
* Workaround to implicit nullable deprecation errors in PHP 8.4.
262+
*
263+
* "Implicitly marking parameter $xxx as nullable is deprecated,
264+
* the explicit nullable type must be used instead"
265+
*/
266+
private function isImplicitNullableDeprecationError(string $message, ?string $file = null, ?int $line = null): bool
267+
{
268+
if (
269+
PHP_VERSION_ID >= 80400
270+
&& str_contains($message, 'the explicit nullable type must be used instead')
271+
) {
272+
log_message(
273+
LogLevel::WARNING,
274+
'[DEPRECATED] {message} in {errFile} on line {errLine}.',
275+
[
276+
'message' => $message,
277+
'errFile' => clean_path($file ?? ''),
278+
'errLine' => $line ?? 0,
279+
]
280+
);
281+
282+
return true;
283+
}
284+
285+
return false;
286+
}
287+
256288
/**
257289
* Checks to see if any errors have happened during shutdown that
258290
* need to be caught and handle them.

0 commit comments

Comments
 (0)