Skip to content

Static call to instance method stdClass::method() #4550

@ngmy

Description

@ngmy

Bug report

0.12.64 (Also https://phpstan.org/)

I get the following error on the $class::values(); line.

Static call to instance method stdClass::values().

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

class Test
{
    /**
     * @template T
     * @psalm-param class-string<T> $class
     */
    public static function valuesOf(string $class): void
    {
        (new $class())->values(); // No error
        assert(method_exists($class, 'values')); // No effect
        $class::values(); // Error
    }
}

https://phpstan.org/r/020e6a92-b651-41a1-9c6d-6992da1b35b5

Expected output

I expect to get no errors.
Why is it recognized as stdClass and why do I get an error?
Also, is there a workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions