Why can't i make generics work on phpstorm ?

Hello, i've phpstorm 2023.2.2 and i'm trying to make a base generics example work, but without succes. The example is taken directly from this Jetbrain's video:

https://www.youtube.com/watch?v=uLX1ZE2xQeI&t=126s

this is my code:

 

why can't i get the autocomplete suggestion on the object ? 

is there some special tool to install to make phpstorm recognize generics ?

0

Hi,

Looks like, you are missing →items after getUsers() here:

Could you please double-check that?

0

Thanks Vasily, this way it works. 

Is there some way to make phpstorm understand that the collection is an iterable object, and thus infer the $user type variable in the foreach, without accessing directly the items property ?

0

Hi,

Do you want to have something like this?

0

yes, with further researches i managed to obtain this result using this istruction on my collection:

@implements \IteratorAggregate<T>

now when i have a Collection object i can iterate over it and the type  T is recognised. Thanks !

0

请先登录再写评论。