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
Unnecessary EmptyArrayAccess
after checking if key exists
#7120
Comments
I found these snippets: https://psalm.dev/r/b4217d10dd<?php
$testing = [];
if (array_key_exists('a', $testing)) {
$a = $testing['a'];
}
|
The code, as presented, is pointless, as |
@weirdan I think there maybe something different with our setup to the playground. The test code we were working with is <?php
/** @return array<array-key, string> */
function get_array(): array { return []; }
function get_string(): string { return 'a'; }
function get_int(): int {
/** @psalm-trace $array */
$array = get_array();
/** @psalm-trace $counts */
$counts = array_count_values($array);
if (array_key_exists(get_string(), $counts)) {
return $counts[get_string()];
}
return 0;
} Both environments give the same type for We are on For now we can fix our code by adding a var comment to the differing type and that seems to be a acceptable work around for us. |
Playground is running |
@weirdan thank you, I have run our code on |
https://psalm.dev/r/b4217d10dd
The text was updated successfully, but these errors were encountered: