How to type hint list of arrays?

I don't know if I'm missing something - I want to type hint an array of structured arrays just like I can do so with array of objects. For example:

/**
* @return array<array{id: int, name: string}>
*/

or:

/**
* @return array{id: int, name: string}[]
*/

meaning this is a numbered array or iterator where each element is an array with keys id and name. How can I do this?

I found a feature request here https://youtrack.jetbrains.com/issue/WI-61694/Feature-request-ability-to-describe-array-of-arrays-collections-in-PHPDoc where the answer is that this is already supported by using attributes and Psalm/Phpstan notation but I couldn't find what the notation really looks like. How can I type hint arrays like this in PhpStorm?

 

0
2 comments

I might be missing the point but apparently, your scenario is covered by this ticket:
https://youtrack.jetbrains.com/issue/WI-65168

0

Thanks, yes, this might be it. I was hoping this feature was already supported but it appears it's not.

0

Please sign in to leave a comment.