psalm
psalm copied to clipboard
Disambiguate between class-string and interface-string?
https://psalm.dev/r/73c14dc055
In both of these cases I'd expect one branch of the condition to have a class-string and the other to have an interface-string?
I'm additionally surprised to see class-string|string
is not collapsed to string
I found these snippets:
https://psalm.dev/r/73c14dc055
<?php
/** @var class-string|interface-string $type1 */
if (interface_exists($type1)) {
/** @psalm-trace $type1 */
} else {
/** @psalm-trace $type1 */
}
/** @var class-string|interface-string $type2 */
if (class_exists($type2)) {
/** @psalm-trace $type2 */
} else {
/** @psalm-trace $type2 */
}
Psalm output (using commit 4b2c698):
INFO: Trace - 5:0 - $type1: interface-string
INFO: Trace - 7:0 - $type1: class-string|string
INFO: Trace - 12:0 - $type2: class-string
INFO: Trace - 14:0 - $type2: string