为什么在实体构造函数中使用setter或field key会给出不同的结果?
问题描述:
在__construct
函数中使用$this->type = 'theme';
时,下面是我的实体Theme
的新实例的转储。为什么在实体构造函数中使用setter或field key会给出不同的结果?
ExplorerController.php on line 197:
Theme {#450 ▼
-id: null
-headings: ArrayCollection {#449 ▶}
-infos: null
-base: null
-deletedAt: null
-key: null
-description: null
-type: null
+"type": "theme"
}
我不明白为什么最后一个字段型出现了两次,先用null
值,然后在前面的“+”号引号之间。
如果我使用的setter $this->setType('theme');
则如预期的结果:
ExplorerController.php on line 197:
Theme {#450 ▼
-id: null
-headings: ArrayCollection {#449 ▶}
-infos: null
-base: null
-deletedAt: null
-key: null
-description: null
-type: "theme"
}
我猜它与代理的事,但这样的问题,我不完全理解。
有人可以解释这里发生了什么?
答
-
type
前面的破折号表示它是私人会员。 - A plus表示公共成员。
通过明确设置$this->type
,您正在设置公共成员。
没有真正看到你的代码,除了确保你没有定义$type
两次(也许在扩展类或特征?)之外,我不能提供任何其他建议。
您能否为我们提供您的实体代码? – olibiaz