【发布时间】:2020-10-22 07:31:47
【问题描述】:
使用此代码:
$notis = [
new InternalNotification([
$this->receiver()->associate(User::first()->id),
'product_id' => 1,
'notification_id' => 1,
'is_read' => false,
]),
];
如何确保在第 3 行 ($this->) 上获取 InternalNotification 的当前实例?
【问题讨论】:
-
你不能。
$this指的是其方法包含该代码的对象。 -
问题没有意义,您的阵列看起来有点时髦。它是关联的还是数字的?如果您想要对 InternalNotification 的引用,请将其分配给 var,
$this在方法内部工作,而不是在构造函数的参数内部工作。 -
您不能在发送给构造函数的参数中引用新实例,因为参数是在调用函数之前进行评估的。