Shopware uses the following annotations to define arrays:

I am not sure, if this is annotation is correct and should be working. But intelephense as for now does not recognize it correctly:

I think this is psalm syntax and is not currently supported
Why not using @return array|int[]|string[] instead?
The first element is the key type not a value union type
It would be great if intelephense supported generic/template types. It's not just pslam, phpstan too will have support for it soon. So these annotations are becoming defacto standard.
https://arnaud.le-blanc.net/post/phpstan-generics.html
https://psalm.dev/docs/annotating_code/templated_annotations/
Even phan supports generic types https://github.com/phan/phan/wiki/Generic-Types.
So it's 3 (most) popular static analyzers.
Hello, this issue was closed, but AFAICT this hasn't been implemented yet?
@jaydiablo It is implemented:
/** @var array<string,(float|int)> */
$arr = [];
foreach($arr as $k=>$v){
$k; // string
$v; // float|int
}
@KapitanOczywisty thanks for the reply! We're seeing a case where Intelephense doesn't see the type of items of a collection (implements IteratorAggregate), but we've noticed that Psalm doesn't either (PHPStan does), so looking into it more. If I find it's something that Intelephense should be detecting I'll create a new issue.
Thanks!
Most helpful comment
Even phan supports generic types https://github.com/phan/phan/wiki/Generic-Types.
So it's 3 (most) popular static analyzers.