Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior
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.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat