Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Doctrine create an entity without call __construct method when fetch from repository?

I wrote next code in constructor:

public function __construct()
{
    die('creating entity');
}

When I create instance of entity with new operator like:

$entity = new Entity();

I see the creating entity text.

But when I get entity from repo:

$em->getRepository('AcmeDemoBundle:Entity')->find(1)

Doctrine create an object of entity without calling __construct() method and I don't see the creating entity text.

Can anybody explain how Doctrine creating an object when loading them from repository?

like image 283
Victor Bocharsky Avatar asked Aug 26 '14 14:08

Victor Bocharsky


1 Answers

To create an instance without invoking constructor available with ReflectionClass::newInstanceWithoutConstructor

Doctrine create instances of mapped entities without invoking constructor in Doctrine\ORM\Mapping\ClassMetadataInfo::newInstance()

like image 71
Victor Bocharsky Avatar answered Oct 08 '22 18:10

Victor Bocharsky