PHP - 尝试迭代整数时的 PHPDoc 类型提示

问题描述 投票:0回答:1

我有这个代码

/** @var array{total: integer, records: array} $response */
$response = $this->getResponse();

foreach($response['total'] as $value) {
    $this->saveRecord($value);
}

PhpStorm 不应该使用 PHPDoc 静态分析向我发出警告,提示我正在尝试迭代

$response['total']
,这是一个整数吗?

php phpstorm phpdoc
1个回答
0
投票

您的注释有误;

total
应该是
array<int>
而不仅仅是
integer

有了正确的注释,至少你会在

mixed|int
上得到
$value

不幸的是,它仍然不会触发类型不匹配检查,因为

mixed
WI-61678

© www.soinside.com 2019 - 2024. All rights reserved.