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

str_pos() Requires Only Strings

str_pos() accepted integers as second argument, and would convert them into their equivalent ASCII char. This was a hidden feature of PHP.

Since PHP 8.0, the integer is converted to string as is, and used for the search.

PHP code

<?php

var_dump(strpos('abc ', 32));

?>

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
int(3)

After

bool(false)

PHP version change

This behavior changed in 8.0.

Error Messages

Analyzer

© 2023-2026, Damien Seguy - Exakat