Skip to content

Interface method reported to not exist in spite of manual check #6147

@phinor

Description

@phinor

Bug report

Currently using phpstan 1.2.0, analysis on Level 6

Methods not specifically defined in a type-hinted interface, but which are specifically checked for, are flagged by PHPStan.

Code snippet that reproduces the problem

class Controller
{
    /**
     * @param class-string<ControllerInterface> $class
     * @return void
     */
    public static function invokeController (string $class): void
    {
        if (/* Http::methodIs ("post") && */ method_exists ($class, "methodPost"))
        {
            $class::methodPost (); // Call to an undefined static method ControllerInterface::methodPost()
        }
    }
}

interface ControllerInterface
{

}

Expected output

No error is expected because the method's existence is specifically checked and verified.

Did PHPStan help you today? Did it make you happy in any way?

Yes! Thank you for everything you've done to make our lives as developers better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions