Skip to content

Restore ReflectionClass template covariance in PHP 8.4 stub#11866

Open
roxblnfk wants to merge 1 commit into
vimeo:6.xfrom
roxblnfk:fix/reflectionclass-covariance-php84-stub
Open

Restore ReflectionClass template covariance in PHP 8.4 stub#11866
roxblnfk wants to merge 1 commit into
vimeo:6.xfrom
roxblnfk:fix/reflectionclass-covariance-php84-stub

Conversation

@roxblnfk

@roxblnfk roxblnfk commented Jun 4, 2026

Copy link
Copy Markdown

The PHP 8.4 stub (added in 21fe8ef to type the lazy-object methods) redeclares ReflectionClass with an invariant @template T of object, dropping the @template-covariant used by the base Reflection.phpstub and Php80.phpstub. Because a redeclaration with an explicit @template overrides the inherited one, analysing code against PHP 8.4/8.5 makes ReflectionClass<Foo> no longer assignable to ReflectionClass<object>, producing false-positive InvalidArgument errors.

The Php81/Php82 stubs redeclare ReflectionClass without an @template line and therefore correctly inherit the covariant parameter; only the 8.4 stub regressed. Restore @template-covariant T as object to match the base stub.

Adds a regression test (gated to php_version 8.4) that fails on the 8.4/8.5 CI runners without this change.

The PHP 8.4 stub (added in 21fe8ef to type the lazy-object methods) redeclares ReflectionClass with an invariant `@template T of object`, dropping the `@template-covariant` used by the base Reflection.phpstub and Php80.phpstub. Because a redeclaration with an explicit @template overrides the inherited one, analysing code against PHP 8.4/8.5 makes `ReflectionClass<Foo>` no longer assignable to `ReflectionClass<object>`, producing false-positive InvalidArgument errors.

The Php81/Php82 stubs redeclare ReflectionClass without an @template line and therefore correctly inherit the covariant parameter; only the 8.4 stub regressed. Restore `@template-covariant T as object` to match the base stub.

Adds a regression test (gated to php_version 8.4) that fails on the 8.4/8.5 CI runners without this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant