0

If you have a function that takes an array as one of it's parameters, how would one specify the keys for the array?

I was thinking something to represent:

array(
    'name' => 'foo'
    'email' => 'foo@bar.net'
);

could be

@param array $user [name, email]

A solution that works in PHPStorm would be great!

Bonus: how can you specify if the key is optional?

Roshan Bhumbra
  • 540
  • 1
  • 8
  • 17
  • what do you mean "how would one specify the keys for the array?" ? What do you want to achieve with that? – olibiaz Apr 29 '16 at 15:34
  • updated question for clarity @oli – Roshan Bhumbra Apr 29 '16 at 15:37
  • Thanks, but what do you want to achieve with Phpstorm, you want the editor marks you the index as invalid if its not specified in the doc? The part "works in PHPStorm" seems strange to me. This editor let you use any index without checking it. You want more strict behaviour? – olibiaz Apr 29 '16 at 15:44
  • @oli yes, pretty much – Roshan Bhumbra Apr 29 '16 at 15:47
  • 1
    There is no strictness check for array keys. For code completion help you can install `Options completion plugin` -- it uses [phpDocumentor's hash description](https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md#7-describing-hashes). – LazyOne Apr 29 '16 at 16:11

0 Answers0