exxecc exxecc - 1 year ago 162
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?


@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 Source

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){}    
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download