Using ORM
$timer = new Timer();
$em->persist($timer);
print $timer->getId(); //blank - not yet set
$em->flush($timer);
print $timer->getId(); //prints ID of newly inserted record
Actual ORM Code (Doctrine)
public function persist($entity)
{
if ( ! is_object($entity)) {
throw ORMInvalidArgumentException::invalidObject('EntityManager#persist()' , $entity);
}
$this->errorIfClosed();
$this->unitOfWork->persist($entity);
}
Question
How does Doctrine insert insert_id into the Entity, when the ORM's code above has no "pass by reference" directive?
I.e. normally I'd expect something like this:
public function persist(&$entity)
{
...
}
to indicate that the entity will be modified (with insert_id) during the persist process. But there is nothing of the sort. Nevertheless, Entity is populated with insert_id magically.
How does that happen exactly?
