Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPDoc - Specify the type of array keys

Tags:

arrays

php

phpdoc

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?

like image 766
MikO Avatar asked Jun 23 '14 21:06

MikO


1 Answers

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.

like image 109
Emmanuel Guiton Avatar answered Sep 23 '22 08:09

Emmanuel Guiton