开发者

code hinting / completion for array of Objects in Zend Studio (or any other Eclipse based IDE)

开发者 https://www.devze.com 2023-01-28 22:16 出处:网络
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!

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号