PHP annotation array (key, value)

I am working with Netbeans 8.0.2.

Is there a way to declare (and using course autocomplete) the array key and value types of the @return array annotation?

how

@return array[string]Class2

      

Or how:

@return Class2[string]

      

This way Netbeans should have no problem with autocomplete with the following foreach:

foreach($aArray as $sString => $oClass2){ ... }

      

I am aware of the following annotation method:

@return Class2[]

      

But this way I have no idea how to get the autocomplete on the string key.

Of course "String" is not autocomplete, but let's say we want to add another Object instead of a string as a key, then how can I tell my IDE to tell it and get the autocomplete correct?

+3


source to share


2 answers


I am using netbeans and works well this way:

/* @var $data['a'] \SomeClass */
/* @var $data['b'] string */
$data = array(
  "a" => new \SomeClass(),
  "b" => "Dump string"
);

      



It is important to use single * when creating this type of comment in netbeans.

+1


source


As far as I know, the key cannot be set, but you can enter the value in the foreach loops like this:



/**
 * $var $value MyTypeHint
 */
foreach($array as $key => $value){}    

      

+2


source







All Articles