3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Eclipse PDOで配列内のオブジェクトをコード補完する

Posted at
hoge.php
class hoge {

	private $id = NULL;
	
	public function setId( $id ) {
		$this -> id = $id;
	}
	
	public function getId() {
		return $this -> id;
	}
}
php fuga.php
class fuga {
	
	/**
	 * hogeオブジェクト配列
	 * @var array
	 */
	private $hogeArray = array();
	
	public function getHogeArray() {
		return $this -> hogeArray;
	}
	
}

という2つのクラスがあり、fugaクラスの$hogeArrayの要素は、全てhogeオブジェクトだったとする。

そのような時に、

$fuga = new fuga();

foreach ( $fuga -> getHogeArray() as $hoge ) {
	
	$hoge -> ge
}

と入力すれば、$hoge -> getId()と補完して欲しいところなんだけど、Eclipse的には$hogeArrayの要素がhogeオブジェクトだとは分からないので、当然、補完してくれない。

そんな時はfugaクラスのコメントを以下のようにする。

php fuga.php
class fuga {
	
	/**
	 * hogeオブジェクト配列
	 * @var array[hoge]
	 */
	private $hogeArray = array();
	
	public function getHogeArray() {
		return $this -> hogeArray;
	}
	
}

これで、補完してくれるようになりましたー。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?