Skip to content

Commit f045730

Browse files
authored
Merge pull request #10598 from weirdan/key_exists-is-an-alias-for-array_key_exists
2 parents fd1294e + 6e2effa commit f045730

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2055,7 +2055,9 @@ protected static function hasNonEmptyCountCheck(PhpParser\Node\Expr\FuncCall $st
20552055

20562056
protected static function hasArrayKeyExistsCheck(PhpParser\Node\Expr\FuncCall $stmt): bool
20572057
{
2058-
return $stmt->name instanceof PhpParser\Node\Name && strtolower($stmt->name->getFirst()) === 'array_key_exists';
2058+
return $stmt->name instanceof PhpParser\Node\Name
2059+
&& (strtolower($stmt->name->getFirst()) === 'array_key_exists'
2060+
|| strtolower($stmt->name->getFirst()) === 'key_exists');
20592061
}
20602062

20612063
/**

tests/TypeReconciliation/ArrayKeyExistsTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,19 @@ public function isCriticalError(int|string $key): bool {
507507
'ignored_issues' => [],
508508
'php_version' => '8.0',
509509
],
510+
'keyExistsAsAliasForArrayKeyExists' => [
511+
'code' => <<<'PHP'
512+
<?php
513+
/**
514+
* @param array<string, string> $arr
515+
*/
516+
function foo(array $arr): void {
517+
if (key_exists("a", $arr)) {
518+
echo $arr["a"];
519+
}
520+
}
521+
PHP,
522+
],
510523
];
511524
}
512525

0 commit comments

Comments
 (0)