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

Non-covariant method doesn't trigger an error when return type declaration is missing #8081

Closed
johnbillion opened this issue Sep 29, 2022 · 2 comments

Comments

@johnbillion
Copy link
Contributor

Bug report

When a method's return type is covariant with its grandparent class but not its parent class, PHPStan doesn't detect this problem even though it triggers a fatal error in PHP at runtime.

Code snippet that reproduces the problem

Expected output

I expect this to trigger an error

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

The levels system in PHPStan is a great feature, it's allowing me to gradually refactor a large project level by level. Cheers!

@phpstan-bot
Copy link
Contributor

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

@@ @@
-No errors
+PHP 7.4 – 8.2 (1 error)
+==========
+
+19: Return type mixed of method three::foo() is not covariant with return type array of method two::foo().
+
+PHP 7.1 – 7.3 (1 error)
+==========
+
+19: Return type mixed of method three::foo() is not compatible with return type array of method two::foo().
Full report

PHP 7.4 – 8.2 (1 error)

Line Error
19 Return type mixed of method three::foo() is not covariant with return type array of method two::foo().

PHP 7.1 – 7.3 (1 error)

Line Error
19 Return type mixed of method three::foo() is not compatible with return type array of method two::foo().

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 Dec 11, 2023
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

3 participants