我有一个数组中的自定义对象(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} */ } }
是的,尝试:
原文链接:https://www.f2er.com/php/130828.htmlforeach($this->collection as $podcast) { /* @var $podcast Podcast */ $r .= '<li>' . $podcast->getTitle() . '</ }
自从我使用Eclipse已经有一段时间了,但我记得它曾经在那里工作.