exxecc exxecc - 7 months ago 51
PHP Question

PHP Annotation Array (Key, Value)

I work with Netbeans 8.0.2.

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

Like:

@return array[string]Class2


Or like:

@return Class2[string]


So Netbeans should have no problems with autocomplete on following foreach:

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


I know about the following way of annotation:

@return Class2[]


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

Sure, "String" - there is no autocomplete, but let's say we want to add another Object instead a string as Key, then how could I inform my IDE to let it know and to get the right autocomplete?

Answer

As far as I know the key can't be typehinted, but you can typehint the value in foreach loops like this:

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