psalm icon indicating copy to clipboard operation
psalm copied to clipboard

`is_a` not respected when result assigned to variable

Open HypeMC opened this issue 1 year ago • 1 comments

Currently, the result of is_a() is not respected when it's assigned to a variable.

https://psalm.dev/r/387b538c3f

HypeMC avatar Feb 02 '24 15:02 HypeMC

I found these snippets:

https://psalm.dev/r/387b538c3f
<?php

interface Foo {}
interface Bar extends Foo {
    public static function bar(): int;
}

/**
 * @param class-string<Foo> $foo
 */
function foo(string $foo): void
{
    $isBar = is_a($foo, Bar::class, true);
    
    if ($isBar) {
        $foo::bar();
    }
    
    if (is_a($foo, Bar::class, true)) {
        $foo::bar();
    }
}
Psalm output (using commit bf57d59):

ERROR: UndefinedMethod - 16:9 - Method Foo::bar does not exist

psalm-github-bot[bot] avatar Feb 02 '24 15:02 psalm-github-bot[bot]