Edw*_*uay 10 php eclipse intellisense type-hinting code-completion
我在一个数组中有一组自定义对象(Podcast).
当我使用foreach循环迭代这个集合时,我没有对包含从集合中拉出的对象的变量进行代码完成(例如我在C#/ VisualStudio中).
有没有办法给PHP一个类型提示,以便Eclipse知道从集合中拉出的对象的类型,以便它可以向我展示intellisense中该对象的方法?

<?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;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
谢谢,Fanis,我更新了我的FOREACH模板以自动包含该行:
if(count(${lines}) > 0) {
foreach(${lines} as ${line}) {
/* @var $$${var} ${Type} */
}
}
Run Code Online (Sandbox Code Playgroud)

Fan*_*nis 19
是的,试试:
foreach($this->collection as $podcast) {
/* @var $podcast Podcast */
$r .= '<li>' . $podcast->getTitle() . '</
}
Run Code Online (Sandbox Code Playgroud)
自从我使用Eclipse以来已经有一段时间,但我记得它曾经在那里工作过.
| 归档时间: |
|
| 查看次数: |
2970 次 |
| 最近记录: |