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

Final classes should bypass static check #3120

Closed
muglug opened this issue Mar 24, 2020 · 3 comments
Closed

Final classes should bypass static check #3120

muglug opened this issue Mar 24, 2020 · 3 comments
Labels
Milestone

Comments

@muglug
Copy link
Contributor

muglug commented Mar 24, 2020

Bug report

<?php

class A {
    /** @return static */
    public static function getInstance() {
		$class = static::class;
        return new $class();
    }
}

final class AChild extends A {
    public static function getInstance() {
        return new AChild();
    }
}

Expected: no issue
Actual: Method AChild::getInstance() should return static(AChild) but returns AChild

https://phpstan.org/r/2c338741-4eae-443a-b677-e832a81ca29a

Slightly related to #3118

@phpstan-bot
Copy link
Contributor

@muglug PHPStan now reports different result with your code snippet:

@@ @@
-13: Method AChild::getInstance() should return static(AChild) but returns AChild.
+ 5: Method A::getInstance() has no return typehint specified.
+12: Method AChild::getInstance() has no return typehint specified.
Full report
Line Error
5 Method AChild::getInstance() has no return typehint specified.
12 Method AChild::getInstance() has no return typehint specified.

@phpstan-bot
Copy link
Contributor

@muglug After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-13: Method AChild::getInstance() should return static(AChild) but returns AChild.
+No errors

@github-actions
Copy link

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 Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants