Doctrine uses proxy objects to represent related objects in order to facilitate lazy loading. This is a really cool feature, but its causing an issue with something I am trying
@mustaccio, @Heather Orr
I had this problem. Thanks for idea,
This is the code:
// $object is a Proxy class
$objectClass = get_class($object);
$reflectionClass = new \ReflectionClass($objectClass);
// Make sure we are not using a Proxy class
if ($obj instanceof Proxy) {
$reflClass = $reflClass->getParentClass();
}
Another way, if you just need to read annotations:
// $object is a Proxy class
$objectClass = get_class($object);
$classMetadata = $this->em->getClassMetadata($objectClass);
foreach ($classMetadata->getReflectionProperties() as $property) {
$annotation = $this->annotationReader->getPropertyAnnotation($property, YOUR_ANNOTATION::class)
}
Not absolutely related to original question, but I hope this will help some people...