我正在使用 Netbeans 6.9 并编写一个实现 Iterator 接口的 PHP 类。当我迭代对象中的项目时,我希望 IDE 提供 Intellisense。它似乎适用于 Zend 框架,因为我注意到当迭代 Zend_Db_Rowset 时,我会得到 Zend_DB_Row 的智能感知。例如,当我写:
foreach($rowset as $row) {
$row->delete();
}
当我键入“$row->”时,Netbeans 会弹出 Zend_Db_Row_Abstract 的成员函数的代码提示。不幸的是,我不能让它为我自己的代码工作。以下是我尝试开始工作的示例:
class Foo {
private $value;
/**
*
* @param string $value
*/
public function setValue($value) {
$this->value = $value;
}
/**
*
* @return string
*/
public function getValue() {
return $this->value;
}
}
class It implements Iterator {
private $data;
public function __construct($data) {
$this->data = $data;
}
/**
*
* @return Foo
*/
public function current() {
return current($this->data);
}
/**
*
* @return Foo
*/
public function key() {
return key($this->data);
}
/**
*
* @return Foo
*/
public function next() {
return next($this->data);
}
/**
*
* @return Foo
*/
public function rewind() {
return reset($this->data);
}
/**
*
* @return bool
*/
public function valid() {
return key($this->data) !== null;
}
}
$a = new Foo();
$b = new Foo();
$a->setValue('Hello');
$b->setValue('Bye');
$testData = array($a, $b);
$myIt = new It($testData);
foreach ($myIt as $obj) {
echo $obj->getValue();
}
奇怪的是,intellisense 似乎认为 $obj 是 It 类型的对象,而我希望它认为(实际上它是)Foo 类型的对象。