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 方法的情况下创建实体?
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
