In calls to mb_ functions, silently transform arg into string

In PHP8, a number of functions who were accepting null arguments will only accept
string ones.

In the polyfill, mb_* functions are declared with a trict type checking of "string".

Therefore, we deprecate the use of non string arguments, so that it won't break when either using the polyfill,
or future php8 versions.
This commit is contained in:
Pierre-Olivier Vares 2021-02-22 09:25:14 +01:00
parent 4ee48c44e5
commit ac45be2580
1 changed files with 4 additions and 0 deletions

View File

@ -47,6 +47,8 @@ abstract class Helper implements HelperInterface
*/
public static function strlen($string)
{
$string = (string) $string;
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return \strlen($string);
}
@ -65,6 +67,8 @@ abstract class Helper implements HelperInterface
*/
public static function substr($string, $from, $length = null)
{
$string = (string) $string;
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return substr($string, $from, $length);
}