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

Phan reports an error for trait methods that have a return type hint of static and a return value of $this #4845

Open
TFLI-DB opened this issue Mar 20, 2024 · 0 comments

Comments

@TFLI-DB
Copy link

TFLI-DB commented Mar 20, 2024

Problem

If a method in a trait has the return type hint static and returns $this Phan will report an error like:

PhanTypeMismatchReturn Returning $this of type \TestTrait but test() is declared to return static

Demo

https://phan.github.io/demo/?code=%3C%3Fphp%0Atrait+TestTrait+%7B%0A++++public+function+test%28%29+%3A+static+%7B%0A++++++++return+%24this%3B%0A++++%7D%0A%7D%0A%0Aclass+TestClass+%7B%0A++++use+TestTrait%3B%0A%7D%0A%0A%24tc+%3D+new+TestClass%28%29%3B%0A%24tc-%3Etest%28%29%3B

Discovery Phan version info

Phan 5.4.3
php-ast version 1.1.1
PHP version used to run Phan: 8.1.27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant