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

Cannot override trait method #2935

Closed
rosasurfer opened this issue Jan 31, 2020 · 3 comments
Closed

Cannot override trait method #2935

rosasurfer opened this issue Jan 31, 2020 · 3 comments

Comments

@rosasurfer
Copy link

rosasurfer commented Jan 31, 2020

There already are a few issues discussing using trait and class inheritance together but it seems to me none of them really fit my observation (I may be wrong) .

I'm trying to override a trait method the way the official PHP documentation shows but PHPStan complains. Please see the example:
https://phpstan.org/r/3cd9314c-002d-4796-b9ce-4715c57650da

On 3v4l.org the code executes just fine. Any hints? Thank you.

class A {
}
class B extends A {
    public function bar() : bool {
        return true;
    }
}
trait T {
    public function bar() : bool {
        return parent::bar();
    }
}
class C extends A {
    use T;

    public function bar() : bool {
        return false;
    }
}

var_dump((new C())->bar());
@ondrejmirtes
Copy link
Member

This is a very special case. Basically what you're asking for is: Do not analyse trait's method in a class where that method is overriden.

@ondrejmirtes
Copy link
Member

Implemented: phpstan/phpstan-src@a2044e6

@lock
Copy link

lock bot commented Jun 24, 2020

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.
BTW: Did you know that PHPStan now has a brand new website with a user guide, guide to writing analyser-friendly PHP code, and a guide to developing PHPStan extensions? Visit phpstan.org today!

@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants