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
7 changes: 6 additions & 1 deletion src/Type/Accessory/HasOffsetValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use PHPStan\Type\Traits\MaybeArrayTypeTrait;
use PHPStan\Type\Traits\MaybeCallableTypeTrait;
use PHPStan\Type\Traits\MaybeIterableTypeTrait;
Expand Down Expand Up @@ -266,7 +268,10 @@ public function searchArray(Type $needleType): Type
$needleType instanceof ConstantScalarType && $this->valueType instanceof ConstantScalarType
&& $needleType->getValue() === $this->valueType->getValue()
) {
return $this->offsetType;
return new UnionType([
new IntegerType(),
new StringType(),
]);
}

return new MixedType();
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/array-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function normalArrays(array $arr, string $string): void
}

if (array_key_exists(17, $arr) && $arr[17] === 'foo') {
assertType('17', array_search('foo', $arr, true));
assertType('int', array_search('foo', $arr, true));
assertType('int|false', array_search('foo', $arr));
assertType('int|false', array_search($string, $arr, true));
}
Expand Down
Loading