You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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();
}
}
The text was updated successfully, but these errors were encountered:
…9381)
* [GH-9380] Bugfix: Delegate ReflectionEnumProperty::getAttributes().
* [GH-9380] Add test for retrieving attributes via enum property.
* [GH-9380] Add test for retrieving attributes via enum property.
* [GH-9380] Call parent ReflectionProperty ctor for best behavior.
* Update tests/Doctrine/Tests/ORM/Functional/EnumTest.php
Co-authored-by: Grégoire Paris <[email protected]>
Co-authored-by: Grégoire Paris <[email protected]>
* 2.12.x:
Allow using Enum from different namespace than Entity (doctrine#9384)
Corrected ORM version and added missing dependency (doctrine#9386)
PHPStan 1.4.0 (doctrine#9385)
[doctrineGH-9380] Bugfix: Delegate ReflectionEnumProperty::getAttributes(). (doctrine#9381)
Support enum cases as parameters (doctrine#9373)
Add detach as of list cascade-all operations (doctrine#9357)
Bug Report
Summary
An Error "Internal error: Failed to retrieve the reflection object" is thrown when calling
AttributeReader::getPropertyAnotations
because the inherited functionReflectionProperty::getAttributes()
is not called on the original reflection property in theReflectionEnumProperty
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
Expected behavior
The expected behaviour should return the property attributes like
ReflectionProperty::getAttributes()
is supposed to. A possible solution could be extending theReflectionEnumProperty
class with an inheritedgetAttributes
method, that will return the attributes from the original reflection property.The text was updated successfully, but these errors were encountered: