diff --git a/resources/functionMap.php b/resources/functionMap.php index 2b31468b37..1308d22342 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -6318,7 +6318,8 @@ 'mb_decode_mimeheader' => ['string', 'string'=>'string'], 'mb_decode_numericentity' => ['string', 'string'=>'string', 'convmap'=>'array', 'encoding'=>'string'], 'mb_detect_encoding' => ['string|false', 'str'=>'string', 'encoding_list='=>'mixed', 'strict='=>'bool'], -'mb_detect_order' => ['bool|list', 'encoding_list='=>'non-empty-list|non-falsy-string'], +'mb_detect_order' => ['bool', 'encoding_list'=>'non-empty-list|non-falsy-string'], +'mb_detect_order\'1' => ['list'], 'mb_encode_mimeheader' => ['string', 'str'=>'string', 'charset='=>'string', 'transfer_encoding='=>'string', 'linefeed='=>'string', 'indent='=>'int'], 'mb_encode_numericentity' => ['string', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string', 'is_hex='=>'bool'], 'mb_encoding_aliases' => ['list|false', 'encoding'=>'string'], diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index f37e4e3b93..a972ac4f51 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -86,7 +86,8 @@ 'getenv\'1' => ['array', 'varname='=>'null', 'local_only='=>'bool'], 'ldap_set_rebind_proc' => ['bool', 'ldap'=>'resource', 'callback'=>'?callable'], 'mb_decode_numericentity' => ['string|false', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string'], - 'mb_detect_order' => ['bool|list', 'encoding_list='=>'non-empty-list|non-falsy-string|null'], + 'mb_detect_order' => ['bool', 'encoding_list'=>'non-empty-list|non-falsy-string'], + 'mb_detect_order\'1' => ['list', 'encoding_list='=>'null'], 'mb_encoding_aliases' => ['list', 'encoding'=>'string'], 'mb_str_split' => ['list', 'str'=>'string', 'split_length='=>'positive-int', 'encoding='=>'string'], 'mb_strlen' => ['0|positive-int', 'str'=>'string', 'encoding='=>'string'], diff --git a/tests/PHPStan/Analyser/nsrt/bug-8922-php74.php b/tests/PHPStan/Analyser/nsrt/bug-8922-php74.php new file mode 100644 index 0000000000..1a0af68920 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-8922-php74.php @@ -0,0 +1,19 @@ + $array + * @param non-falsy-string $string + * @param mixed $mixed + */ +function doSomething($array, $string, $mixed): void +{ + assertType('list', mb_detect_order()); + assertType('bool', mb_detect_order(null)); + assertType('bool', mb_detect_order($array)); + assertType('bool', mb_detect_order($string)); + assertType('bool', mb_detect_order($mixed)); +} diff --git a/tests/PHPStan/Analyser/nsrt/bug-8922.php b/tests/PHPStan/Analyser/nsrt/bug-8922.php new file mode 100644 index 0000000000..d7e39b5a14 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-8922.php @@ -0,0 +1,19 @@ += 8.0 + +namespace Bug8922; + +use function PHPStan\Testing\assertType; + +/** + * @param non-empty-list $array + * @param non-falsy-string $string + * @param mixed $mixed + */ +function doSomething($array, $string, $mixed): void +{ + assertType('list', mb_detect_order()); + assertType('list', mb_detect_order(null)); + assertType('bool', mb_detect_order($array)); + assertType('bool', mb_detect_order($string)); + assertType('bool|list', mb_detect_order($mixed)); +} diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 7d83fec5f9..0063dd35e6 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -2248,6 +2248,21 @@ public function testBug12954(): void $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12954.php'], []); } + public function testBug8922(): void + { + $errors = []; + if (PHP_VERSION_ID < 80000) { + $errors[] = [ + 'Parameter #1 $encoding_list of function mb_detect_order expects non-empty-list|non-falsy-string, null given.', + 15, + '• Type #1 from the union: null is not a list. +• Type #1 from the union: null is empty.', + ]; + } + + $this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-8922.php'], $errors); + } + public function testBug13065(): void { $errors = [];