strpos() With Null Haystack¶
PHP accepted null as first parameter $string of strpos(). Then, it cast the null to empty string, and returned immediately false, as nothing was found in such string.
Since PHP 8.2, this is a deprecated behavior, with a warning message. It will be removed in PHP 9.
PHP code¶
<?php
var_dump(strpos(null, '1'));
?>
Before¶
false
After¶
strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
PHP version change¶
This behavior was deprecated in 8.2
This behavior changed in 9.0