File tree 2 files changed +16
-1
lines changed
src/Psalm/Internal/Analyzer/Statements/Expression
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -2055,7 +2055,9 @@ protected static function hasNonEmptyCountCheck(PhpParser\Node\Expr\FuncCall $st
2055
2055
2056
2056
protected static function hasArrayKeyExistsCheck (PhpParser \Node \Expr \FuncCall $ stmt ): bool
2057
2057
{
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 ' );
2059
2061
}
2060
2062
2061
2063
/**
Original file line number Diff line number Diff line change @@ -507,6 +507,19 @@ public function isCriticalError(int|string $key): bool {
507
507
'ignored_issues ' => [],
508
508
'php_version ' => '8.0 ' ,
509
509
],
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
+ ],
510
523
];
511
524
}
512
525
You can’t perform that action at this time.
0 commit comments