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

self::class in parameter on trait method #4066

Closed
olivernybroe opened this issue Nov 10, 2020 · 8 comments
Closed

self::class in parameter on trait method #4066

olivernybroe opened this issue Nov 10, 2020 · 8 comments
Labels

Comments

@olivernybroe
Copy link

Bug report

Phpstan crashes when using a trait that has a method with a parameter that refers to self::class

Code snippet that reproduces the problem

https://phpstan.org/r/bddbfc71-bae5-49a2-9d64-0472e559781b

Expected output

That it doesn't crash ;)

@ondrejmirtes
Copy link
Member

Wow, didn't know such thing is possible... Runtime proof: https://3v4l.org/P7Bmd

@olivernybroe
Copy link
Author

@ondrejmirtes Yeah, took me some time to debug it throughout our application :) But finally found the line!

we learn something new each day ;)

@ondrejmirtes
Copy link
Member

Interesting reflection behaviour that I'll need to replicate: https://3v4l.org/iopRK

@phpstan-bot
Copy link
Contributor

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

@@ @@
 -1: Internal error: Failed to find parent class of constant "class".
 Run PHPStan with --debug option and post the stack trace to:
-https://github.com/phpstan/phpstan/issues/new
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
Full report
Line Error
-1 Internal error: Failed to find parent class of constant "class".
Run PHPStan with --debug option and post the stack trace to:
https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

@phpstan-bot
Copy link
Contributor

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

@@ @@
--1: Internal error: Failed to find parent class of constant "class".
-Run PHPStan with --debug option and post the stack trace to:
-https://github.com/phpstan/phpstan/issues/new
+ 7: Parameter $date of method HelloWorld::sayHello() has invalid typehint type DateTimeImutable.
Full report
Line Error
7 Parameter $date of method HelloWorld::sayHello() has invalid typehint type DateTimeImutable.

@ondrejmirtes
Copy link
Member

Fixed by: ondrejmirtes/BetterReflection@a41da9f + phpstan/phpstan-src@431905c

@olivernybroe
Copy link
Author

Amazing! Thanks

@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