strpos() Does Not Accept False¶
PHP used to type cast false
to 0 then to a string, when it is used as second argument to strpos().
PHP code¶
<?php
var_dump(strpos('abc', false));
var_dump(strpos('a'.chr(0), false));
?>
Before¶
PHP Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /codes/strposWithFalse.php on line 3
Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /codes/strposWithFalse.php on line 3
bool(false)
int(1);
After¶
int(0)
int(0)
PHP version change¶
This behavior was deprecated in 7.4
This behavior changed in 8.0