diff --git a/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php b/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php index af63cc047d..c9de826666 100644 --- a/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php @@ -58,7 +58,7 @@ public function specifyTypes( } $key = $node->getArgs()[0]->value; $array = $node->getArgs()[1]->value; - $keyType = $scope->getType($key); + $keyType = $scope->getType($key)->toArrayKey(); $arrayType = $scope->getType($array); if ( diff --git a/tests/PHPStan/Analyser/nsrt/bug-11724.php b/tests/PHPStan/Analyser/nsrt/bug-11724.php new file mode 100644 index 0000000000..baf4c01658 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-11724.php @@ -0,0 +1,15 @@ + 'hello']; + assertType('true', array_key_exists($f, $a)); + if (array_key_exists($f, $a)) { + assertType('5.0', $f); + assertType("array{5: 'hello'}", $a); + } +}