Zend Studio(或任何其他Eclipse IDE)中对象数组的代码提示 /完成
-
29-09-2019 - |
题
这甚至可能吗?例如,说我有一系列狗。如何使代码完成工作?这是说明问题的代码。任何建议都很棒!
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 = new Dog('scoobi');
$Scoobi-> // code hinting / completion works!
$dogs = Dog::init_many(array('scoobi', 'lassie', 'bingo'));
$dogs[0]-> // code hinting / completion doesn't work!
解决方案
一个间接的方法可能是
$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
}
其他提示
在Zend Studio 11中我使用:
/**
*
* @return Dog[]
*/
public static function init_many(array $names) {
foreach ($names as $n) {
$collection[] = new self($n);
}
return $collection;
}
不隶属于 StackOverflow