PHPStorm + PHPdoc - can I type an individual array element?

I have:

$myarr['DB'] = new DB(); $myarr['config'] = new config(); 

Can I somehow PHPStorm find out what exactly is inside these keys? So far I see only hints of the variables and properties of the class, but not the keys of the array.

+8
source share
5 answers

You can predefine the keys of the array, then suggest PHPStorm (CTRL + space)

 $my = array(); $my['qwe'] = ''; $my['asd'] = ''; $my['zxc'] = ''; $my['']// inside '' will be autosuggest 

You can also use phpdoc (CTRL + Q):

 /** * keys: * <pre> * some_array (array) * some_bool (boolean) * some_double (double) * some_nice_integer (integer) * </pre> * @return array */ public function toArray(){ // return some array } 
+3
source

This functionality is not yet implemented in PhpStorm. Vote for array support .

You can also try the silex plugin .

0
source

For an arbitrary array, PHPStorm has no idea about the keys that are used in any array, and therefore does not give hints. You can even prove that it is impossible to reliably implement such a function, so I think you are out of luck here.

Collected from:

Stop request response

0
source

https://plugins.jetbrains.com/plugin/9927-deep-assoc-completion

Type hints from associative array like a champ

Image from github repo plugin. I use the plugin and can confirm that it works as described.

0
source
 $obj = (object)[]; // Cast empty array to object add properties: $obj->x = 'some' $obj->y = 'hints' 

Now, PHPStorm, when typing $obj-> ..... hints at x and y

-1
source

All Articles