The mb_convert_encoding() function accepts either a string or an array as parameter 1. Its return type is the same type as parameter 1's type.
PHPStan understands this with base PHP. But when using Safe, the return type of mb_convert_encoding() is always string|array regardless of the type of parameter 1.
Consider:
// `mb_convert_encoding()` is passed a string and will therefore return a string (and not an array)
$foo = \mb_convert_encoding('string', 'utf-8');
// Got expected PHPStan output, because `stripos()` expects a string and got a string.
$baz = stripos($foo, '');
// Now using the Safe version...
$bar = \Safe\mb_convert_encoding('string', 'utf-8');
// Failure: PHPStan outputs `Parameter #1 $haystack of function stripos expects string, array|string given.`
// The Safe version returns type string|array even though the input was a string
$baz = stripos($bar, '');
The
mb_convert_encoding()function accepts either a string or an array as parameter 1. Its return type is the same type as parameter 1's type.PHPStan understands this with base PHP. But when using Safe, the return type of
mb_convert_encoding()is alwaysstring|arrayregardless of the type of parameter 1.Consider: