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

前端 未结 1 1543
旧时难觅i
旧时难觅i 2020-12-10 04:03

Does anyone know how this works?

1条回答
  •  醉梦人生
    2020-12-10 05:00

    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 讨论(0)
提交回复
热议问题