Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
11.2
-
None
-
None
Description
When using types on the elements of an Iterator, then the IDE detects the wrong types while iterating via foreach.
The variable "$item" in the source code is of type "Model" and the IDE should suggest the properties of "Model". But it thinks "$item" is of type \TestIterator and suggests methods and properties of the \TestIterator type.
Run code completion on $item within the foreach to reproduce this issue.
class Model { public $name = "test"; } class TestIterator extends \ArrayIterator { public function __construct(\Model ...$items) { parent::__construct($items); } public function current(): \Model { return parent::current(); } public function offsetGet($offset): \Model { return parent::offsetGet($offset); } } $iterator = new \TestIterator(new Model(), new Model()); foreach ($iterator as $item) { # run code completion on $item to reproduce issue echo $item; }