mb_strrpos() Third Argument Is Not Encoding¶
The third argument of mb_strrpos() was the offset where to start the search in the string. It was often 0, although the 4th argument was the encoding. Since the encoding was more often used, and the offset forgotten, mb_strrpos() used to recognize the encoding when it is used in position 3, and use it. In PHP 8.0, it is not the case anymore.
PHP code¶
<?php
// Valid in PHP 7.x
echo mb_strrpos('abc', 'a', 'utf8');
// Valid in PHP 8.+
echo mb_strrpos('abc', 'a', 0, 'utf8');
echo mb_strrpos('abc', 'a', encoding: 'utf8');
?>
Before¶
PHP Deprecated: mb_strrpos(): Passing the encoding as third parameter is deprecated. Use an explicit zero offset in /codes/mb_strrpos.php on line 3
Deprecated: mb_strrpos(): Passing the encoding as third parameter is deprecated. Use an explicit zero offset in /codes/mb_strrpos.php on line 3
0
After¶
PHP Fatal error: Uncaught TypeError: mb_strrpos(): Argument #3 ($offset) must be of type int, string given in /codes/mb_strrpos.php:3
Stack trace:
#0 /codes/mb_strrpos.php(3): mb_strrpos('abc', 'a', 'utf8')
#1 {main}
thrown in /codes/mb_strrpos.php on line 3
Fatal error: Uncaught TypeError: mb_strrpos(): Argument #3 ($offset) must be of type int, string given in /codes/mb_strrpos.php:3
Stack trace:
#0 /codes/mb_strrpos.php(3): mb_strrpos('abc', 'a', 'utf8')
#1 {main}
thrown in /codes/mb_strrpos.php on line 3
PHP version change¶
This behavior changed in 8.0