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

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');

?>

Alternatives

  • Use named parameters.
  • Add a 0 as third parameter (the default value for offset).

In more recent PHP versions, this error message is now :ref: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