Skip to content

Commit

Permalink
Merge pull request #10598 from weirdan/key_exists-is-an-alias-for-arr…
Browse files Browse the repository at this point in the history
…ay_key_exists
  • Loading branch information
weirdan authored Jan 29, 2024
2 parents fd1294e + 6e2effa commit f045730
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/TypeReconciliation/ArrayKeyExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,19 @@ public function isCriticalError(int|string $key): bool {
'ignored_issues' => [],
'php_version' => '8.0',
],
'keyExistsAsAliasForArrayKeyExists' => [
'code' => <<<'PHP'
<?php
/**
* @param array<string, string> $arr
*/
function foo(array $arr): void {
if (key_exists("a", $arr)) {
echo $arr["a"];
}
}
PHP,
],
];
}

Expand Down

0 comments on commit f045730

Please sign in to comment.