-
Notifications
You must be signed in to change notification settings - Fork 510
DynamicReturnTypeExtensions: allow hooking on object #2761
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
DynamicReturnTypeExtensions: allow hooking on object #2761
Conversation
|
||
public function getClass(): string | ||
{ | ||
return 'object'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic strings like this are a no-go :) We need a new specific extension type. I'd imagine the interface can look the same, without the getClass
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, how do we name it?
Or how about returning null here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, object::class
works, so it is not a magic string anymore :D https://3v4l.org/rrvKH
nvm, that is nonsense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd prefer null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented null version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name isn't that important 😊 It can be "ClasslessDynamicMethodReturnTypeExtension".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classless is a good prefix! But I assume I should wait for this
I've got a completely different and much more universal idea how to solve this, stay tuned 😊 |
So I worry that we might need to add many more extensions to be able to describe universally all these situations. What I propose is a new
It would be called right at the beginning of MutatingScope::resolveType. Returning null means "I'm not interested in this expression". This mechanism would also be able to replace not-really-flexible overriding of scopeClass, because we can only have one for the whole analysis. Feel free to prototype it 😊 |
Added extension as requested, but I think it needs to be |
Closing in favor of #2789 |
To support stuff like phpstan/phpstan-doctrine#499