Skip to content

Stop using deprecated ClassMetadata::getReflectionProperty() - #96

Merged
mpdude merged 2 commits into
mainfrom
avoid-deprecated-reflection-property-access
Nov 26, 2026
Merged

mpdude merged 2 commits into
mainfrom
avoid-deprecated-reflection-property-access

Conversation

@mpdude

@mpdude mpdude commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Doctrine ORM 3.8 deprecates direct access to ClassMetadata::$reflFields. It will be removed in ORM 4.0, doctrine/orm#11659. ClassMetadata::getReflectionProperty() is itself deprecated for the same reason, since it still reads from that array internally.

This PR replaces those calls with ReflectionService::getAccessibleProperty(), the same non-deprecated pattern already used elsewhere in TranslatableClassMetadata.

A naive replacement using the entity's own class name broke properties declared in mapped superclasses, since PHP's ReflectionProperty cannot resolve a private property by name when given a subclass. The declaring class is now read from the field/association mapping's declared entry instead, mirroring what Doctrine does internally.

Doctrine ORM 3.8 deprecates direct access to `ClassMetadata::$reflFields`, which will be removed in ORM 4.0. `getReflectionProperty()` is itself deprecated for the same reason, since it still reads from that array internally, so every call to it triggered a deprecation warning.

Replace those calls with `ReflectionService::getAccessibleProperty()`, the same non-deprecated pattern this class already uses in `findTranslatedProperties()`. A naive replacement using the current class name broke properties declared in mapped superclasses, since PHP's `ReflectionProperty` cannot resolve a private property by name when given a subclass. The declaring class is now read from the field/association mapping's `declared` entry, mirroring what Doctrine does internally.

Doctrine ORM 2 represents mappings as plain arrays rather than `FieldMapping`/`AssociationMapping` objects, so the helper handles both representations to keep working across the `doctrine/orm: ^2.13 || ^3.0` range this bundle supports.
@mpdude
mpdude merged commit 07aa4bb into main Nov 26, 2026
8 checks passed
@mpdude
mpdude deleted the avoid-deprecated-reflection-property-access branch November 26, 2026 21:50
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