我有这个代码
/** @var array{total: integer, records: array} $response */
$response = $this->getResponse();
foreach($response['total'] as $value) {
$this->saveRecord($value);
}
PhpStorm 不应该使用 PHPDoc 静态分析向我发出警告,提示我正在尝试迭代
$response['total']
,这是一个整数吗?
您的注释有误;
total
应该是 array<int>
而不仅仅是 integer
。
有了正确的注释,至少你会在
mixed|int
上得到 $value
。
不幸的是,它仍然不会触发类型不匹配检查,因为
mixed
:WI-61678