Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Doctrine 2 retrieve entities without calling the entity's constructor?

Does anyone know how this works?

like image 413
blacktie24 Avatar asked Jul 02 '11 05:07

blacktie24


1 Answers

This works by unserializing objects. Unserializing in PHP does prevent the constructor to be called as the serialized object has been already constructed.

Create an object without calling it's constructor in PHP:

$className = 'stdClass'; # set classname here
$serialized = sprintf('O:%d:"%s":0:{}', strlen($className), $className);
$object = unserialize($serialized);

For more details please see this article: Doctrine 2: Give me my constructor back

like image 90
hakre Avatar answered Oct 28 '22 00:10

hakre