strpos() With Out-Of-Range Offset Is A Fatal Error

Requesting a large offset, beyond the size of the searched string, leads to a Fatal error in PHP 8.0 and more recent.

Until then, it was a warning.

This error message is shared by several PHP native and extension functions, namely mbstring and iconv: strpos(), strrpos(), stripos(), strripos(), mb_strpos(), mb_strrpos(), mb_stripos(), mb_strripos(), iconv_strpos and iconv_strrpos.

PHP code

<?php

strpos('abc', 'b', 6);

?>

Before

PHP Warning:  strpos(): Offset not contained in string -

Warning: strpos(): Offset not contained in string -

After

PHP Fatal error:  Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -

Fatal error: Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) -

PHP version change

This behavior changed in 8.0

Error Messages