Typehints for generic PHP collections doesn't work for me

I tried to use new generic type hints feature in the following way:

1. I created a repository class with getAllForPage method.

/**
* @param Page $page
* @return Collection<Reaction>
*/
public function getAllForPage(Page $page): Collection
{
return new ArrayCollection($this->findBy(['page' => $page]));
}

2. Then I tried to DI that repository into my class and get advantage of type hints. As you can see the reactions variable is typed as Doctrine Collection and reaction variable inside foreach is typed as mixed.

Am I doing something wrong?

 

1 comment
Comment actions Permalink

Sorry for leaving you without a reaction here.

Just for anyone else, here is the YouTrack ticket:
https://youtrack.jetbrains.com/issue/WI-62236

0

Please sign in to leave a comment.