Query
$em->getRepository($this->getRepositoryName(\'AppBundle:User\'))->find($id);
return object instance of Proxies\\__CG__\\A
Doctrine is giving you a proxy object from an auto-generated class that extends your entity and implements \Doctrine\ORM\Proxy\Proxy
. You can view the code for these auto-generated classes in app/cache/dev/doctrine/orm/Proxies/
.
The proxy object allows for a set of behaviors that Doctrine provides that you would otherwise have to explicitly code into your entity, including support for lazy-loading of properties. For example, if your object has a reference to another entity (such as from a OneToOne
/OneToMany
/ManyToOne
/ManyToMany
association), you don't necessarily want to always load those references when you retrieve your User
record, because they may not be relevant all the time. Lazy-loading allows that data to be brought in later on-demand.
In order to perform that lazy loading, the entity needs to have access to Doctrine so it can ask Doctrine to retrieve the relevant data. This is done through an __initializer__
property that is provided to the proxy object. The rest then happens, handled by Doctrine, without your code needing to know the details.