Skip to content

Commit 4d77e98

Browse files
committed
InArrayFunctionTypeSpecifyingExtension - fix calls with less than 2 parameters
1 parent 1c9e90f commit 4d77e98

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ public function isFunctionSupported(FunctionReflection $functionReflection, Func
3838
public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes
3939
{
4040
$isStrictComparison = false;
41-
if (count($node->getArgs()) >= 3) {
41+
$argsCount = count($node->getArgs());
42+
if ($argsCount >= 3) {
4243
$strictNodeType = $scope->getType($node->getArgs()[2]->value);
4344
$isStrictComparison = (new ConstantBooleanType(true))->isSuperTypeOf($strictNodeType)->yes();
4445
}
4546

47+
if ($argsCount < 2) {
48+
return new SpecifiedTypes();
49+
}
50+
4651
$needleType = $scope->getType($node->getArgs()[0]->value);
4752
$arrayType = $scope->getType($node->getArgs()[1]->value);
4853
$arrayValueType = $arrayType->getIterableValueType();

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ public function testBug1843(): void
347347
$this->assertNoErrors($errors);
348348
}
349349

350+
public function testBug9711(): void
351+
{
352+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-9711.php');
353+
$this->assertCount(1, $errors);
354+
$this->assertSame('Function in_array invoked with 1 parameter, 2-3 required.', $errors[0]->getMessage());
355+
}
356+
350357
public function testBug4713(): void
351358
{
352359
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4713.php');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace Bug9711;
4+
5+
echo in_array(new \stdClass());

0 commit comments

Comments
 (0)