PHP - PHPDoc typehint when trying to iterate over integer

83 views Asked by At

I have this code

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

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

Shouldn't PhpStorm give me a warning using PHPDoc static analysis that I'm trying to iterate over $response['total'], which is an integer ?

1

There are 1 answers

2
Eugene Morozov On

At the moment, we add the mixed type to all array shapes, that is why the inspection isn't triggered.

You can check what type any symbol holds by selecting it and clicking View | Type Info.

enter image description here Please vote for WI-61678.