ReflectionEnumProperty throws error on AttributeReader::getPropertyAnnotations() #6911

Closed
opened 2026-01-22 15:41:09 +01:00 by admin · 0 comments
Owner

Originally created by @ezkimo on GitHub (Jan 14, 2022).

Originally assigned to: @beberlei on GitHub.

Bug Report

Q A
BC Break no
Version 2.11.0

Summary

An Error "Internal error: Failed to retrieve the reflection object" is thrown when calling AttributeReader::getPropertyAnotations because the inherited function ReflectionProperty::getAttributes() is not called on the original reflection property in the ReflectionEnumProperty class.
In my specific case I 'm using custom annotations I have to read for custom behaviour. When trying to retrieve the custom annotations the error occurs.

Current behavior

When trying to fetch all or a specific annotation of an entity property, the call fails with an error "Internal error: Failed to retrieve the reflection object".

How to reproduce

enum Suit: string {
    case Hearts = 'H';
    case Diamonds = 'D';
    case Clubs = 'C';
    case Spades = 'S';
}

#[Entity]
class Card
{
    /** ... */

    #[Column(type: 'string', enumType: Suit::class)]
    #[AnyCustomAnnotation(param: 'bla')]
    public $suit;
}

/** ... */

// @var \Doctrine\ORM\EntityManager
$metadata = $objectManager->getClassMetadata(Card::class);

foreach ($metadata->fieldMappings as $field => $mapping) {
    $property = $metadata->getReflectionProperty($field);
    // @var Doctrine\ORM\Mapping\Driver\AttributeReader
    $isCustom = $reader->getPropertyAnnotation($property, AnyCustomAnnotation::class);
    /** ... */
}

Expected behavior

The expected behaviour should return the property attributes like ReflectionProperty::getAttributes() is supposed to. A possible solution could be extending the ReflectionEnumProperty class with an inherited getAttributes method, that will return the attributes from the original reflection property.

class ReflectionEnumProperty extends ReflectionProperty
{
    ...
    /**
     * {@inheritDoc}
     */
     public function getAttributes(?string $name = null, int $flags = 0): array
     {
         return $this->originalReflectionProperty->getAttributes();
     }
}
Originally created by @ezkimo on GitHub (Jan 14, 2022). Originally assigned to: @beberlei on GitHub. ### Bug Report | Q | A |------------ | ------ | BC Break | no | Version | 2.11.0 #### Summary An Error "Internal error: Failed to retrieve the reflection object" is thrown when calling `AttributeReader::getPropertyAnotations` because the inherited function `ReflectionProperty::getAttributes()` is not called on the original reflection property in the `ReflectionEnumProperty` class. In my specific case I 'm using custom annotations I have to read for custom behaviour. When trying to retrieve the custom annotations the error occurs. #### Current behavior When trying to fetch all or a specific annotation of an entity property, the call fails with an error "Internal error: Failed to retrieve the reflection object". #### How to reproduce ``` enum Suit: string { case Hearts = 'H'; case Diamonds = 'D'; case Clubs = 'C'; case Spades = 'S'; } #[Entity] class Card { /** ... */ #[Column(type: 'string', enumType: Suit::class)] #[AnyCustomAnnotation(param: 'bla')] public $suit; } /** ... */ // @var \Doctrine\ORM\EntityManager $metadata = $objectManager->getClassMetadata(Card::class); foreach ($metadata->fieldMappings as $field => $mapping) { $property = $metadata->getReflectionProperty($field); // @var Doctrine\ORM\Mapping\Driver\AttributeReader $isCustom = $reader->getPropertyAnnotation($property, AnyCustomAnnotation::class); /** ... */ } ``` #### Expected behavior The expected behaviour should return the property attributes like `ReflectionProperty::getAttributes()` is supposed to. A possible solution could be extending the `ReflectionEnumProperty` class with an inherited `getAttributes` method, that will return the attributes from the original reflection property. ``` class ReflectionEnumProperty extends ReflectionProperty { ... /** * {@inheritDoc} */ public function getAttributes(?string $name = null, int $flags = 0): array { return $this->originalReflectionProperty->getAttributes(); } } ```
admin added the Bug label 2026-01-22 15:41:09 +01:00
admin closed this issue 2026-01-22 15:41:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6911