【问题标题】:code hinting / completion for array of Objects in Zend Studio (or any other Eclipse based IDE)Zend Studio(或任何其他基于 Eclipse 的 IDE)中对象数组的代码提示/完成
【发布时间】:2010-12-01 21:23:57
【问题描述】:

这甚至可能吗?例如,假设我有一组 Dogs。如何让代码完成工作?这是说明问题的代码。任何建议都会很棒!

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!

【问题讨论】:

标签: eclipse autocomplete zend-studio code-completion code-hinting


【解决方案1】:

一种间接的方法可以是

$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
}

【讨论】:

    【解决方案2】:

    在 Zend Studio 11 中,我使用:

    /**
    * 
    * @return Dog[]
    */
    public static function init_many(array $names) {
        foreach ($names as $n) {
            $collection[] = new self($n);
        }
        return $collection;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      • 2014-03-03
      • 2010-11-09
      • 2012-05-04
      • 1970-01-01
      • 2010-09-05
      • 1970-01-01
      相关资源
      最近更新 更多