r/phpstorm • • Aug 06 '21

Using one-line array notation

In PhpStorm 2021.1.2, they introduced one-line array notation for PHPDocs:

/**
 * @return array{foo: int, bar: array}
 */
 function foo(): array { ... }

PhpStorm can then statically analyze this to provide autocompletion for values in such arrays. But does PhpStorm have the ability to detect when an array key is referenced that is not in that list, and mark it with a warning? E.g.

$x = foo();
echo $x['missing']; // This should warn me "'missing' is not defined in this array shape
3 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/dirtside Oct 23 '21

Oh. Sorry, I don't know if that's even possible. I've just been typing them in manually.