Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

key_exists() is not treated as an alias of array_key_exists() #10346

Closed
lens0021 opened this issue Nov 4, 2023 · 1 comment · Fixed by #10598
Closed

key_exists() is not treated as an alias of array_key_exists() #10346

lens0021 opened this issue Nov 4, 2023 · 1 comment · Fixed by #10598
Labels

Comments

@lens0021
Copy link
Contributor

lens0021 commented Nov 4, 2023

https://psalm.dev/r/6cf8c987e4

Copy link

I found these snippets:

https://psalm.dev/r/6cf8c987e4
<?php

/**
 * @return array{
 * 	foo?: string,
 * }
 */
function foo() {
    return array_filter([
        'foo' => rand(0,1) === 1 ? 'foo' : null,
    ]);
}

$foo = foo();
if (array_key_exists('foo', $foo)) {
    echo $foo['foo'];
}

if (key_exists('foo', $foo)) {
    echo $foo['foo'];
}
Psalm output (using commit 7233f38):

ERROR: PossiblyUndefinedArrayOffset - 20:10 - Possibly undefined array key $foo['foo'] on array{foo?: string}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants