Frage

Ist das überhaupt möglich? Zum Beispiel, sagen, dass ich eine Reihe von Hunden habe. Wie kann ich Code-Vervollständigung an der Arbeit? Hier ist Code, um das Problem zu veranschaulichen. Jede Beratung wäre toll!

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!
War es hilfreich?

Lösung

Ein indirekter Weg, dies zu tun sein könnte

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

Andere Tipps

In Zend Studio 11 I Verwendung:

/**
* 
* @return Dog[]
*/
public static function init_many(array $names) {
    foreach ($names as $n) {
        $collection[] = new self($n);
    }
    return $collection;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top