开发者

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

开发者 https://www.devze.com 2023-03-16 17:19 出处:网络
Does anyone know how this 开发者_如何学编程works?This works by unserializing objects. Unserializing in PHP does prevent the constructor to be called as the serialized object has been already construct

Does anyone know how this 开发者_如何学编程works?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消