diff --git a/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php b/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php index 10cf27ef802..fa1644f1821 100644 --- a/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php @@ -56,7 +56,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, if (count($keyTypes) !== count($valueTypes)) { if ($this->phpVersion->throwsTypeErrorForInternalFunctions()) { - return null; + return new NeverType(); } return new ConstantBooleanType(false); } diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 976f2004764..fa8f6d7bc19 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -4555,7 +4555,7 @@ public function dataArrayFunctions(): array 'array_combine([1], [2])', ], [ - PHP_VERSION_ID < 80000 ? 'false' : 'array', + PHP_VERSION_ID < 80000 ? 'false' : '*NEVER*', 'array_combine([1, 2], [3])', ], [ diff --git a/tests/PHPStan/Analyser/data/array-combine-php7.php b/tests/PHPStan/Analyser/data/array-combine-php7.php index e40184184bf..0ff9f4399be 100644 --- a/tests/PHPStan/Analyser/data/array-combine-php7.php +++ b/tests/PHPStan/Analyser/data/array-combine-php7.php @@ -78,3 +78,8 @@ function withNonEmptyArray(array $a, array $b): void { assertType("non-empty-array<'bar'|'baz'|'foo', 'apple'|'avocado'|'banana'>|false", array_combine($a, $b)); } + +function withDifferentNumberOfElements(): void +{ + assertType('false', array_combine(['foo'], ['bar', 'baz'])); +} diff --git a/tests/PHPStan/Analyser/data/array-combine-php8.php b/tests/PHPStan/Analyser/data/array-combine-php8.php index 18c0eb6ca27..77b362498bb 100644 --- a/tests/PHPStan/Analyser/data/array-combine-php8.php +++ b/tests/PHPStan/Analyser/data/array-combine-php8.php @@ -78,3 +78,8 @@ function withNonEmptyArray(array $a, array $b): void { assertType("non-empty-array<'bar'|'baz'|'foo', 'apple'|'avocado'|'banana'>", array_combine($a, $b)); } + +function withDifferentNumberOfElements(): void +{ + assertType('*NEVER*', array_combine(['foo'], ['bar', 'baz'])); +}