PHP - Iterator hiding a map, what should `valid` do? -
class map implements \arrayaccess, \iterator { private $map; public function __construct() { $this->map = array(); } /* iterator interface: * abstract public mixed current ( void ) * abstract public scalar key ( void ) * abstract public void next ( void ) * abstract public void rewind ( void ) * abstract public boolean valid ( void ) */ public function current() { return \current($this->map); } public function key() { return \key($this->map); } public function next() { \next($this->map); } public function rewind() { \reset($this->map); } public function valid() { //what should go here? } /*so on*/ to able foreach on structure have implement interface noted in code comments. of them except valid have obvious functions can use apply them map encapsulating.
the example used on iterator page of "list type" keeps count of how far along in array.
what should use implementation valid?
i've answered question.
i finding links documentation , wondered "maybe key..."
a null key makes no sense (even php) , uses [] append operator , stuff. if key returns null, out of bounds.
Comments
Post a Comment