Skip to content

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

Conversation

janedbal
Copy link
Contributor

To support stuff like phpstan/phpstan-doctrine#499


public function getClass(): string
{
return 'object';
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

@janedbal janedbal Nov 22, 2023

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

Copy link
Contributor Author

@janedbal janedbal Nov 22, 2023

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented null version.

Copy link
Member

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".

Copy link
Contributor Author

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

@ondrejmirtes
Copy link
Member

I've got a completely different and much more universal idea how to solve this, stay tuned 😊

@ondrejmirtes
Copy link
Member

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 ExpressionTypeResolverExtension with method:

getType(Expe $expe): ?Type

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 😊

@janedbal
Copy link
Contributor Author

Added extension as requested, but I think it needs to be getType(Expr $expr, Scope $scope): ?Type, see #2789

@janedbal
Copy link
Contributor Author

janedbal commented Dec 1, 2023

Closing in favor of #2789

@janedbal janedbal closed this Dec 1, 2023
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

Successfully merging this pull request may close these issues.

2 participants