2

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 ?

2

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Not sure on this (why array<int>?)... unless I've got the initial example completely wrong...
I totally missed what the question was about. It's about the fact that the OP can iterate over an integer, and not about $value holding the wrong type (even though the root cause is the same). Thank you, I've corrected the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.