Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

$strictArgType = $scope->getType($functionCall->getArgs()[2]->value);
if (!($strictArgType instanceof ConstantBooleanType)) {
return TypeCombinator::union($haystackArgType->getIterableKeyType(), new ConstantBooleanType(false), new NullType());
} elseif ($strictArgType->getValue() === false) {
if (!$strictArgType instanceof ConstantBooleanType || $strictArgType->getValue() === false) {
return TypeCombinator::union($haystackArgType->getIterableKeyType(), new ConstantBooleanType(false));
}

Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ public function dataFileAsserts(): iterable

yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-argument-type.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7788.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7809.php');
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/data/bug-7809.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

namespace Bug7809;

use function array_search;
use function PHPStan\Testing\assertType;

function foo(bool $strict = false): void {
assertType('0|1|2|false', array_search('c', ['a', 'b', 'c'], $strict));
}

function bar(): void{
assertType('2', array_search('c', ['a', 'b', 'c'], true));
}

function baz(): void{
assertType('0|1|2|false', array_search('c', ['a', 'b', 'c'], false));
}