Skip to content

Wrong array key type inferring from the result of static method call on class-string #6404

@javer

Description

@javer

Bug report

Array key which is a value of type int returned from static method called on string prechecked by is_a is wrongly treated as int|string in PHPStan 1.4.1 (there was no error in PHPStan 1.3.1):

class Foo {
    public static function getCode(): int {
        return 1;
    }
}

if (is_a($fooClass, Foo::class, true)) {
    $this->someMap[$fooClass::getCode()] = true;
}
Property Bar::$someMap (array<int, bool>) does not accept array<int|string, bool>.

The issue might be related to #6403, but it looks like a little bit different.

Code snippet that reproduces the problem

https://phpstan.org/r/f2efd61c-09c3-4f12-8694-a353dbb4c245

Expected output

No error should be reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions