关于如何使用PhpDoc注释数组键还有一个未解决的问题:https://github.com/phpDocumentor/phpDocumentor2/issues/650
我尝试了以下符号:
/**
* @return array<string,Someclass>
* @return Someclass[string]
*/
public function someMethod(): array { ... }
,但是PhpStorm似乎无法解决此问题,因此在使用例如
foreach
内部对象是未知的:
foreach($obj->someMethod() as $some) {
$some->methodOfSomeclass(); // PhpStorm -> Method not found
}
我知道我可以使用管道运算符:
@return array<string,Someclass>|Someclass[]
我也知道我可以输入提示变量:
/** @var Someclass $obj */
$obj
但是有没有一种方法可以配置PhpStorm在不使用管道的情况下知道数组值类型?