Skip to content

Commit

Permalink
In calls to mb_ functions, silently transform arg into string
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Yopai committed Feb 22, 2021
1 parent cc8529a commit bee5a5b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function getHelperSet()
*/
public static function strlen($string)
{
$string = (string) $string;

if (false === $encoding = mb_detect_encoding($string, null, true)) {
return \strlen($string);
}
Expand All @@ -65,6 +67,8 @@ public static function strlen($string)
*/
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);
}
Expand Down

0 comments on commit bee5a5b

Please sign in to comment.