diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index 434373b8e3..b6bf21c49f 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -38,11 +38,16 @@ public function isFunctionSupported(FunctionReflection $functionReflection, Func public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes { $isStrictComparison = false; - if (count($node->getArgs()) >= 3) { + $argsCount = count($node->getArgs()); + if ($argsCount >= 3) { $strictNodeType = $scope->getType($node->getArgs()[2]->value); $isStrictComparison = (new ConstantBooleanType(true))->isSuperTypeOf($strictNodeType)->yes(); } + if ($argsCount < 2) { + return new SpecifiedTypes(); + } + $needleType = $scope->getType($node->getArgs()[0]->value); $arrayType = $scope->getType($node->getArgs()[1]->value); $arrayValueType = $arrayType->getIterableValueType(); diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index d4da5e3e9f..53e7ae85ba 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -347,6 +347,13 @@ public function testBug1843(): void $this->assertNoErrors($errors); } + public function testBug9711(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-9711.php'); + $this->assertCount(1, $errors); + $this->assertSame('Function in_array invoked with 1 parameter, 2-3 required.', $errors[0]->getMessage()); + } + public function testBug4713(): void { $errors = $this->runAnalyse(__DIR__ . '/data/bug-4713.php'); diff --git a/tests/PHPStan/Analyser/data/bug-9711.php b/tests/PHPStan/Analyser/data/bug-9711.php new file mode 100644 index 0000000000..b7802d0196 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-9711.php @@ -0,0 +1,5 @@ +