【发布时间】:2016-03-07 15:55:46
【问题描述】:
我给出了以下错误:
Catchable Fatal Error: Argument 1 passed to BackendBundle\Entity\Notification::sendSystemMessage()
must be an instance of BackendBundle\Entity\BackendBundle\Entity\User, instance of
Proxies\__CG__\BackendBundle\Entity\User given
我在 Notification.php 类中的方法是:
/**
* Send System message, to be used after creating a blank one
*
* @param \BackendBundle\Entity\User $reciever
*
* @param string $message
*
* @return Notification
*/
public function sendSystemMessage(BackendBundle\Entity\User $reciever, $message)
{
$this->setReciever($reciever);
$this->setMessage($message);
$this->setTimestamp(new \DateTime());
$this->setReaded(false);
$this->setSystemMessage(true);
return $this;
}
当我使用像 setReciever 这样的 setter 和 getter 时,它工作得很好,但是当我尝试调用多个参数时,我得到了这个错误,我犯了一个错误,或者实体中不能有一个多参数方法上课?
【问题讨论】:
-
该错误消息来自其他地方的代码,您可以在其中调用 sendSystemMessage() 函数。您的 $reciever 参数类型错误。
-
这是我的第一个想法,但我调用 setReciever 方法进行了相同的验证,效果很好
-
什么意思?您能否显示将两者与发送的相同参数以及 setReciever 的函数描述进行比较的代码?
-
在用户类型提示的开头添加反斜杠。更好的是,添加一个 use 语句并简化对 User 的类型提示。 php.net/manual/en/language.namespaces.php
-
这就是问题所在,该死的反斜杠,谢谢!
标签: php symfony parameters doctrine symfony-2.8