I am confused why I get these "problems" in Visual Studio Code when I try to implement an Iterator in PHP. I have not seen these problem messages earlier, so I wonder if the Iterator class has been changed lately? Or is anything else wrong?
See screenshot below with error message in Visual Studio Code.
Here's the code in plain text as well:
<?php
class MyList implements Iterator {
private $my_list = []; // Array of items
private $index = 0;
// Implemented Iterator methods
public function current() { return $this->my_list[$this->index]; }
public function key() { return $this->index; }
public function next() { $this->index++; }
public function rewind() { $this->index = 0; }
public function valid() { return $this->index < count($this->my_list); }
}
?>
