This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
When a class implements iterator and i do a foreach Netbeans does not detect the type of the variable i am getting. example: <?php /** * Description of GroupList */ class Auth_GroupList implements Iterator { public function __construct($array) {} /** * Rewind the iterator */ public function rewind(){} /** * Return the current User * * @return Auth_Group */ public function current() {} /** * @return int Index key */ public function key() {} /** * Get the next in the list */ public function next() {} /** * If the current position is valid * * @return bool */ public function valid() {} } ?> When iterate it like <? $groups = Auth_Group::getAllGroups(); //Will return a Auth_GroupList foreach($groups as $group) { //Group will be of type Auth_Group as returned by current() but Netbeans won't detect this in the autocompetion /* @var $group Auth_Group */ //Will fix it partly the autocompletion still gives the methodes on the Auth_GroupList $group->someMethodeOnAuth_Group(); }
I'm not able to reproduce that form your snippet. Some classes are missing, etc. Provide whole piece of a code, where I can simply invoke CC to see that it doesn't work, please.
I hope this example is more clear: <?php class Auth_Group { public function __construct() { } public function someMethode() { //dummy methode should show in the autocompetion } } /** * Description of GroupList */ class Auth_GroupList implements Iterator { private $var = array(); private $index = 0; public function __construct($array) { if (is_array($array)) { $this->var = $array; $this->size = count($array); } } /** * Rewind the iterator */ public function rewind(){ $this->index = 0; } /** * Return the current User * * @return Auth_Group */ public function current() { return $this->var[$this->index]; } /** * @return int Index key */ public function key() { return $this->index; } /** * Get the next in the list */ public function next() { $this->index++; } /** * If the current position is valid * * @return bool */ public function valid() { return ($this->index < $this->size); } } $array = array(new Auth_Group(), new Auth_Group()); $auth_group = new Auth_GroupList($array); foreach ($auth_group as $group) { //$group-> //Autocompletion here gives the interface of Auth_GroupList //$group->current(); //This is not valid in this context //This should be the interface of Auth_Group as this is the type returned by current //It is possible to force it with /* @var $group Auth_Group */ $group->someMethode(); //But than still the interface of the iterator is there }
Yep, thanks. If you use varDoc, interface methods are still sthere, because the type of "varDocked" variable is merged from all possible types. And one of them is that Auth_GroupList which it gives from the foreach. It could be handled more clearly, but not sure how it will be difficult to handle this Iterator interface correctly. Will try look at it for next release.