Chris Chris - 10 months ago 40
PHP Question

What does PHPDoc "static" return type signify here?

I am working on a Symfony project with entities managed by Doctrine. The following is code from my entity:

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);

is auto-generated by Doctrine. The
method was implemented by myself. The method's PHPDoc header was auto-generated by PhpStorm.

What I cannot understand is the
keyword in my custom method's return type.

From my understanding of the PHPDoc types
signifies that this method returns an instance of the class on which it was called, in this case a

However, I fail to see how this method could ever return a
instance or anything other than an instance of

So what does the
keyword mean here? Is my understanding of the keyword flawed? Or is PhpStorm's auto-generated documentation header simply wrong?


I have looked at the source of doctrine for the matching function and here is the return type :

return new static($filtered);

Phpstorm probably parsed the doctrine source and saw the return static statement in the matching function.