配列内にカスタムオブジェクト(ポッドキャスト)のコレクションがあります。
foreachループを使用してこのコレクションを反復処理する場合、コレクションから引き出されたオブジェクトを含む変数のコード補完がありません(たとえば、C#/ VisualStudioの場合のように)。
PHPにタイプヒントを与えて、Eclipseがコレクションからプルされているオブジェクトのタイプを認識し、そのオブジェクトのメソッドをインテリセンスで表示できるようにする方法はありますか?
<?php
$podcasts = new Podcasts();
echo $podcasts->getListHtml();
class Podcasts {
private $collection = array();
function __construct() {
$this->collection[] = new Podcast('This is the first one');
$this->collection[] = new Podcast('This is the second one');
$this->collection[] = new Podcast('This is the third one');
}
public function getListHtml() {
$r = '';
if(count($this->collection) > 0) {
$r .= '<ul>';
foreach($this->collection as $podcast) {
$r .= '<li>' . $podcast->getTitle() . '</li>';
}
$r .= '</ul>';
}
return $r;
}
}
class Podcast {
private $title;
public function getTitle() { return $this->title; }
public function setTitle($value) { $this->title = $value;}
function __construct($title) {
$this->title = $title;
}
}
?>
補遺
ありがとう、ファニス、FOREACHテンプレートを更新して、その行を自動的に含めました。
if(count(${lines}) > 0) {
foreach(${lines} as ${line}) {
/* @var $$${var} ${Type} */
}
}