Skip to content

Conversation

dg
Copy link
Contributor

@dg dg commented Jan 21, 2020

  • Reflection uses ReflectionNamedType instead of ReflectionType since PHP 7.1
  • added reflection for properties
@dg dg force-pushed the pull-reflection branch from 98aadf1 to 105b376 Compare January 21, 2020 18:34
Copy link
Member

@ondrejmirtes ondrejmirtes Jan 21, 2020

Choose a reason for hiding this comment

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

Hi, thanks for the PR! I disagree with the changes about ReflectionNamedType. I actually went the other way in 0.12.0: b447242

ReflectionNamedType is the only ReflectionType implementation in PHP 7.x, but that will stop being true in PHP 8 where there will also be ReflectionUnionType without the getName() method. So code that's relying on ReflectionNamedType will be broken on PHP 8. I recommend doing something like this instead in your code:

$returnType = $reflectionFunction->getReturnType(); if (!$returnType instanceof ReflectionNamedType) { throw new \Exception('PHP 8 is not yet supported.'); } 

Or maybe even code the support for union types today! :)

Otherwise the PR is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. So I'll turn it around and I'll move getName() and isBuiltin() from ReflectionType to ReflectionNamedType.

@dg dg force-pushed the pull-reflection branch from 105b376 to 32e4629 Compare January 22, 2020 10:29
@ondrejmirtes ondrejmirtes merged commit 57d05a6 into phpstan:master Jan 22, 2020
@ondrejmirtes
Copy link
Member

Perfect, thank you!

@dg dg deleted the pull-reflection branch January 22, 2020 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants