Passing the encoding as third parameter is deprecated. Use an explicit zero offset¶
Description¶
PHP used to recognize automatically the third parameter when it was actually the encoding, and noth the offset of start. The latter is an integer, while the former is a string.
In PHP 8.0, it is now a normal type error.
Example¶
<?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');
?>
Solutions¶
Use named parameters.
Add a 0 as third parameter (the default value for offset).
In more recent PHP versions, this error message is now Argument #%d ($%s) must be of type %s, %s given.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See mb_strrpos.
Static Analysis¶
This error may be tracked down with the following static analysis rules: Structures/MbstringThirdArg.