作者:mobiledu2502928947 | 来源:互联网 | 2023-05-24 16:22
我正在与由Doctrine管理的实体合作开发Symfony项目.以下是我的实体的代码:
class User {
/**
* @ORM\OneToMany(targetEntity="Appointment", mappedBy="user")
*/
private $appointments;
/**
* Get appointments
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getAppointments()
{
return $this->appointments;
}
/**
* Get appointments at a specified date
*
* @param \DateTime $date
* @return \Doctrine\Common\Collections\Collection|static
*/
public function getAppointmentsAtDate(\DateTime $date) {
$allAppointments = $this->getAppointments();
$criteria = Criteria::create()->where(/* some clever filtering logic goes here */);
return $allAppointments ->matching($criteria);
}
}
getAppointments
是由Doctrine自动生成的.该getAppointmentsAtDate
方法由我自己实施.该方法的PHPDoc标头由PhpStorm自动生成.
我无法理解的是static
我的自定义方法的返回类型中的关键字.
根据我对PHPDoc类型的 理解,static
表示此方法返回调用它的类的实例,在本例中为User
实例.
但是,我没有看到此方法如何返回User
实例或除了实例之外的任何其他内容Collection
.
那么static
关键字在这里意味着什么呢?我对关键字的理解是否有缺陷?或者PhpStorm的自动生成的文档标题是错误的?
1> Nico..:
我已经查看了matching
函数的学说来源,这里是返回类型:
return new static($filtered);
Phpstorm可能解析了doctrine源并在匹配函数中看到了返回静态语句.