如何在PHP / Eclipse中获取intellisense对于在foreach循环中从数
发布时间:2020-12-13 14:09:01 所属栏目:PHP教程 来源:网络整理
导读:我有一个数组中的自定义对象(Podcast)的集合. 当我使用foreach循环遍历这个集合时,我没有包含从集合中拉出的对象的变量的代码完成(就像我在C#/ VisualStudio中). 有没有办法给PHP一个类型提示,以便Eclipse知道从集合中拉出的对象的类型,以便它能够告诉我在In
|
我有一个数组中的自定义对象(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;
}
}
?>
附录 感谢Fanis,我更新了我的FOREACH模板,自动添加该行: if(count(${lines}) > 0) {
foreach(${lines} as ${line}) {
/* @var $$${var} ${Type} */
}
}
是的,尝试:
foreach($this->collection as $podcast) {
/* @var $podcast Podcast */
$r .= '<li>' . $podcast->getTitle() . '</
}
自从我使用Eclipse已经有一段时间了,但我记得它曾经在那里工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
