%s(): Passing null to parameter #%d (%s) of type string is deprecated¶
Description¶
Since PHP 8.1, PHP has been enforcing non-null parameters to PHP native functions. Until then, it was possible to use NULL everywhere, and it would have been cast to an empty string or 0. Nowadays, it is a deprecation.
This applies to all PHP native functions, such as, and not limited to: strtolower(), strip_tags(), trim(), addslashes(), strlen(), rtrim(), etc.
Example¶
<?php
strlen(null);
?>
Literal Examples¶
strlen(): Passing null to parameter #1 ($string) of type string is deprecated
Solutions¶
Check the value before calling the function.
Use
??
to convert the null into a suitable default value.