How Doctrine create an entity without call __construct method when fetch from repository?(从存储库获取时,Doctrine 如何在不调用 __construct 方法的情况下创建实体?)
问题描述
我在构造函数中写了下一段代码:
I wrote next code in constructor:
public function __construct()
{
die('creating entity');
}
当我使用 new
运算符创建实体实例时,例如:
When I create instance of entity with new
operator like:
$entity = new Entity();
我看到 creating entity
文本.
但是当我从 repo 中获取实体时:
But when I get entity from repo:
$em->getRepository('AcmeDemoBundle:Entity')->find(1)
Doctrine 创建实体对象而不调用 __construct()
方法,我没有看到 creating entity
文本.
Doctrine create an object of entity without calling __construct()
method and I don't see the creating entity
text.
谁能解释 Doctrine 在从存储库加载对象时如何创建对象?
Can anybody explain how Doctrine creating an object when loading them from repository?
推荐答案
在不调用构造函数的情况下创建实例 ReflectionClass::newInstanceWithoutConstructor
To create an instance without invoking constructor available with ReflectionClass::newInstanceWithoutConstructor
Doctrine 创建映射实体的实例而不在 DoctrineORMMappingClassMetadataInfo::newInstance()
Doctrine create instances of mapped entities without invoking constructor in DoctrineORMMappingClassMetadataInfo::newInstance()
这篇关于从存储库获取时,Doctrine 如何在不调用 __construct 方法的情况下创建实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从存储库获取时,Doctrine 如何在不调用 __construct 方法的情况下创建实体?


基础教程推荐
- php中的PDF导出 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- php中的foreach复选框POST 2021-01-01
- Web 服务器如何处理请求? 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01