Skip to content

Conversation

@greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 2, 2025

This is consistent with other Doctrine projects. Note that I had to add a "covariant" keyword on the template definition of getReflectionClass() return type. That's because since PHP 8.4, ReflectionClass is considered invariant because of lazy objects. Lazy objects introduce new methods to ReflectionClass where the template appears in parameter position, for instance that is the case for isUninitializedLazyObject(). I do not understand why this wasn't an issue with
ReflectionClass::isInstance(), which was introduced way earlier than that though.

The solution I picked is to use "call-site variance", effectively saying that this is OK in this instance (but it might not be, I'm not sure).

The alternative to adding this keyword would be to drop generic information entirely.

See phpstan/phpstan#12459 for more details.

This is consistent with other Doctrine projects. Note that I had to add
a "covariant" keyword on the template definition of getReflectionClass()
return type. That's because since PHP 8.4, ReflectionClass is considered
invariant because of lazy objects. Lazy objects introduce new methods to
ReflectionClass where the template appears in parameter position, for
instance that is the case for isUninitializedLazyObject().
I do not understand why this wasn't an issue with
ReflectionClass::isInstance(), which was introduced way earlier than
that though.

The solution I picked is to use "call-site variance", effectively saying
that this is OK in this instance (but it might not be, I'm not sure).

The alternative to adding this keyword would be to drop generic
information entirely.

See phpstan/phpstan#12459 for more details.
@greg0ire greg0ire added this to the 5.0.0 milestone Nov 3, 2025
@greg0ire greg0ire merged commit 4144e9b into doctrine:5.0.x Nov 3, 2025
8 checks passed
@greg0ire greg0ire deleted the php84-min branch November 3, 2025 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants