简体   繁体   English

Netbeans Intellisense PHP Iterator接口

[英]Netbeans Intellisense PHP Iterator Interface

I'm using Netbeans 6.9 and writing a PHP class that implements the Iterator interface. 我正在使用Netbeans 6.9并编写实现Iterator接口的PHP类。 I would like to have the IDE offer Intellisense as I iterate over the items in my object. 我希望IDE提供Intellisense,因为我迭代了对象中的项目。 It seems to work for the Zend Framework as I've noticed that when iterating over a Zend_Db_Rowset I get intellisense for a Zend_DB_Row. 它似乎适用于Zend框架,因为我注意到当迭代Zend_Db_Rowset时,我得到Zend_DB_Row的intellisense。 For example, when I write: 例如,当我写:

foreach($rowset as $row) {
  $row->delete();
}

When I type "$row->" Netbeans pops up its code hints for the member functions of Zend_Db_Row_Abstract. 当我输入“$ row->”时,Netbeans会弹出Zend_Db_Row_Abstract成员函数的代码提示。 Unfortunately, I can't get this to work for my own code. 不幸的是,我不能让这个为我自己的代码工作。 Below is a sample I tried to get to work: 以下是我试图开始工作的示例:

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();
}

Strangely the intellisense seems to think $obj is an object of type It when I want it to think (and it actually is) an object of type Foo. 奇怪的是,intellisense似乎认为$ obj是类型It的对象,当我希望它(并且它实际上是)Foo类型的对象时。

Within the body of the loop you can provide the type hint in a comment. 在循环体内,您可以在注释中提供类型提示。

/* @var $obj Foo */

+1 for Brian Fisher's suggestion. 为Brian Fisher的建议+1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM