code hinting / completion for array of Objects in Zend Studio (or any other Eclipse based IDE)
Is this even possible? For example, say I have an array of Dogs. How do I get code completion to work? Here's code to illustrate the problem. Any advice would be great!
class Dog {
private $name;
public static function init_many(array $names) {
foreach ($names as $n) {
$collection[] = new self($n);
}
return $collection;
}
public function __construct($n) {
$this->name = $n;
}
public function bark() {
return sprintf('woof! my name is %s',
$this->name
);
}
}
$Scoobi = ne开发者_StackOverfloww Dog('scoobi');
$Scoobi-> // code hinting / completion works!
$dogs = Dog::init_many(array('scoobi', 'lassie', 'bingo'));
$dogs[0]-> // code hinting / completion doesn't work!
An indirect way to do this could be
$dogs = Dog::init_many(array('scoobi', 'lassie', 'bingo'));
foreach ($dogs as & $dog)
{
/* @var $dog Dog */
$dog-> //code hinting works here,
//I use this all the time itereting over doctrine collections
}
In Zend Studio 11 I use :
/**
*
* @return Dog[]
*/
public static function init_many(array $names) {
foreach ($names as $n) {
$collection[] = new self($n);
}
return $collection;
}
精彩评论