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 previous PHP versions, this error message used to be Argument #%d ($%s) must be of type %s, %s given.