How can I specify the type of the keys in the documentation of a PHP method that returns an array?
For example, I use this for an array of objects @return MyClass[]
.
But I want to comment an array like array( 'string' => array( MyClass ) )
, is this possible?
Years after the question, it is possible to document array keys and values using, for example, @return array<integer, string>
for an array of string values indexed by integer keys.
I do not know to what extent this syntax is standard and well supported. Tools such as PHPCS or Psalm do support it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With