Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
phinor opened this issue Dec 3, 2021 · 7 comments · Fixed by phpstan/phpstan-src#1972
Closed

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

phinor opened this issue Dec 3, 2021 · 7 comments · Fixed by phpstan/phpstan-src#1972
Labels
Milestone

Comments

@phinor
Copy link

phinor commented Dec 3, 2021

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.

@mergeable
Copy link

mergeable bot commented Dec 3, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@phinor
Copy link
Author

phinor commented Dec 3, 2021

This bug is not reproducible on phpstan.org which doesn't report the interface method error even without the method_exists check.

@ondrejmirtes
Copy link
Member

Hi, i copied your example to phpstan.org and reproduced it: https://phpstan.org/r/44085bd5-ecf5-45e7-8700-f8f0a5c4e39c

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 3, 2021
@phinor
Copy link
Author

phinor commented Dec 3, 2021

Sorry - forgot the PHP tags... duh. Thank you!

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.9.x, PHPStan now reports different result with your code snippet:

@@ @@
-13: Call to an undefined static method ControllerInterface::methodPost().
+No errors

@ondrejmirtes
Copy link
Member

Fixing bugs by refactoring 🎉 /cc @staabm regression test please

@github-actions
Copy link

github-actions bot commented Dec 8, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants