Skip to content

Conversation

@phansys
Copy link
Contributor

@phansys phansys commented Oct 23, 2023

No description provided.

@phansys phansys marked this pull request as ready for review October 24, 2023 00:21
@phansys phansys requested a review from kocsismate as a code owner October 24, 2023 00:21
@phansys phansys force-pushed the reflection_named_type branch 2 times, most recently from 8a778b4 to b33ad3a Compare October 24, 2023 00:30
@phansys phansys marked this pull request as draft October 24, 2023 01:52
@phansys phansys force-pushed the reflection_named_type branch from b33ad3a to 0bd5391 Compare October 24, 2023 03:49
@phansys phansys changed the title Update stub for ReflectionProperty::getType() [Reflection] Update return types in some stubs Oct 24, 2023

/** @tentative-return-type */
public function getReturnType(): ?ReflectionType {}
public function getReturnType(): ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null {}
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm.. I'm not sure this is the best way to solve your original issue. If we happened to add a new ReflectionType instance then people extending ReflectionFunctionAbstract would have to adapt their return types accordingly. And it is not even going to be possible in a BC way since the class won't be available in older PHP versions.

Please also note that you have to use ./build/gen_stub.php to generate the C header code which we use.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I don't understand the point of this change. ReflectionType exists as a generic interface for anything that can return a type, so making the return type concrete is just... weird.

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 understand the point.
My motivation was to avoid the check for the availability of the getName() method, which is provided by the ReflectionNamedType. IE:

$reflectionProperty = new \ReflectionProperty($object, 'foo');
$reflectionType = $reflectionProperty->getType();

assert($reflectionType instanceof \ReflectionNamedType);

$type = $reflectionType->getName();

But, in view of the current proposal (where ReflectionUnionType and ReflectionUnionType are possible types), I guess this is not a feasible solution.

Thank you so much for your feedback.

@phansys phansys closed this Oct 26, 2023
@phansys phansys deleted the reflection_named_type branch October 26, 2023 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants