diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 8c6aaa03ce3..4cf8e778ee6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -2055,7 +2055,9 @@ protected static function hasNonEmptyCountCheck(PhpParser\Node\Expr\FuncCall $st protected static function hasArrayKeyExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool { - return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'array_key_exists'; + return $stmt->name instanceof PhpParser\Node\Name + && (strtolower($stmt->name->getFirst()) === 'array_key_exists' + || strtolower($stmt->name->getFirst()) === 'key_exists'); } /** diff --git a/tests/TypeReconciliation/ArrayKeyExistsTest.php b/tests/TypeReconciliation/ArrayKeyExistsTest.php index e44bfa55464..4317379eb7b 100644 --- a/tests/TypeReconciliation/ArrayKeyExistsTest.php +++ b/tests/TypeReconciliation/ArrayKeyExistsTest.php @@ -507,6 +507,19 @@ public function isCriticalError(int|string $key): bool { 'ignored_issues' => [], 'php_version' => '8.0', ], + 'keyExistsAsAliasForArrayKeyExists' => [ + 'code' => <<<'PHP' + $arr + */ + function foo(array $arr): void { + if (key_exists("a", $arr)) { + echo $arr["a"]; + } + } + PHP, + ], ]; }