Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/reflection/php_reflection.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function returnsReference(): bool {}
public function hasReturnType(): bool {}

/** @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.


public function hasTentativeReturnType(): bool {}

Expand Down Expand Up @@ -535,7 +535,7 @@ public function getDocComment(): string|false {}
public function setAccessible(bool $accessible): void {}

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

/** @tentative-return-type */
public function hasType(): bool {}
Expand Down Expand Up @@ -614,7 +614,7 @@ public function isEnumCase(): bool {}

public function hasType(): bool {}

public function getType(): ?ReflectionType {}
public function getType(): ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|null {}
}

/** @not-serializable */
Expand Down Expand Up @@ -655,7 +655,7 @@ public function getClass(): ?ReflectionClass {}
public function hasType(): bool {}

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

/**
* @tentative-return-type
Expand Down