-
Notifications
You must be signed in to change notification settings - Fork 667
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
Use ReflectionNamedType instead of ReflectionType (PHP 7.1+) #5204
Conversation
`ReflectionNamedType` has been [introduced in PHP7.1](https://www.php.net/manual/en/class.reflectionnamedtype.php): `class ReflectionNamedType extends ReflectionType` Technically speaking, `ReflectionFunction::getReturnType(): ReflectionType` is a valid construction. But when we use a chain `ReflectionFunction->getReturnType()->getName()`, it's not correct anymore: `getName()` available in ReflectionNamedType but doesn't in ReflectionType. see https://3v4l.org/Y3tvW
@lptn Thank you for your PR. Would you mind rebasing your branch onto the current master? I noticed one important change in your PR, which is to move Meanwhile, #5584 added |
hey @caugner thanks for the feedback! Yes, your concern is valid, |
@lptn Thanks! Let's close this one in favor of that one then. (I can't, but you should be able to.) |
ReflectionNamedType
has been introduced in PHP7.1:class ReflectionNamedType extends ReflectionType
Technically speaking,
ReflectionFunction::getReturnType(): ReflectionType
is a valid construction, but it returnsReflectionNamedFunction
in version PHP 7.1+. The same for other reflection API classes that have getType() or getReturnType() methods.The problem raises when we use a chain
ReflectionFunction->getReturnType()->getName()
, it's not correct anymore:getName()
available inReflectionNamedType
but doesn't inReflectionType
.see https://3v4l.org/0CMfa (tests ReflectionFunction and child)
see https://3v4l.org/Y2Jqo (tests ReflectionProperty::getType())
Related PR on phpstorm-stubs: JetBrains/phpstorm-stubs#1039