Подсказка / завершение кода для массива объектов в Zend Studio (или любой другой IDE на основе Eclipse)

StackOverflow https://stackoverflow.com/questions/4329288

Вопрос

Это вообще возможно? Например, скажем, у меня есть множество собак. Как получить завершение кода для работы? Вот код, чтобы проиллюстрировать проблему. Любой совет будет полезен!

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;
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top