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?
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){}
I am using netbeans and this way work good:
/* @var $data['a'] \SomeClass */
/* @var $data['b'] string */
$data = array(
"a" => new \SomeClass(),
"b" => "Dump string"
);
It is important to use single * when make this type of comments in netbeans.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With