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
Troubles with array_key_exists #10937
Comments
I found these snippets: https://psalm.dev/r/ed6528a596<?php
/**
* @psalm-return ?1
*/
function get_key(): ?int
{
return null;
}
/**
* @psalm-return 1
*/
function get_key_1(): int
{
return 1;
}
function get_key_null(): null
{
return null;
}
/**
* @psalm-return array{1?: int, ''?: int}
*/
function get_keys(): array
{
return [];
}
function test(int $value): int {
return $value;
}
$keys = get_keys();
$key = get_key();
if (array_key_exists($key ?? '', $keys)) {
/** @psalm-trace $keys */;
/** @psalm-trace $key */;
test($keys[$key ?? ''] ?? 1);
}
if (array_key_exists((string)$key, $keys)) {
/** @psalm-trace $keys */;
/** @psalm-trace $key */;
test($keys[(string)$key] ?? 1);
}
$key = get_key_1();
if (array_key_exists($key, $keys)) {
/** @psalm-trace $keys */;
/** @psalm-trace $key */;
test($keys[$key] ?? 1);
}
$key = get_key_null();
if (array_key_exists($key ?? '', $keys)) {
/** @psalm-trace $keys */;
/** @psalm-trace $key */;
test($keys[$key ?? ''] ?? 1);
}
if (array_key_exists((string)$key, $keys)) {
/** @psalm-trace $keys */;
/** @psalm-trace $key */;
test($keys[(string)$key] ?? 1);
}
$key = '';
if (array_key_exists($key, $keys)) {
/** @psalm-trace $keys */;
/** @psalm-trace $key */;
test($keys[$key] ?? 1);
}
|
Can you please describe what the issue is in a short text ? |
@kkmuffme if i.e. if |
Happens because psalm does not store all evaluations but only variables. I don't think this will ever get fixed, especially since you can just assign |
https://psalm.dev/r/ed6528a596
The text was updated successfully, but these errors were encountered: