Intellisense Iterator Interface for Netbeans

I am using Netbeans 6.9 and writing a PHP class that implements the Iterator interface. I would like the IDE to offer Intellisense when I iterate over the elements in my object. This seems to work for the Zend Framework, as I noticed that when repeating through Zend_Db_Rowset I get intellisense for Zend_DB_Row. For example, when I write:

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

When I type "$ row->", Netbeans displays its code hints for the Zend_Db_Row_Abstract member functions. Unfortunately, I cannot get this to work for my own code. Below is the sample I was trying to find:

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

It is strange that intellisense seems to be that $ obj is an object of type It when I want it to think (and actually it is) an object of type Foo.

+3
1

.

/* @var $obj Foo */

+1 .

+2

Source: https://habr.com/ru/post/1773344/


All Articles