PHP: SeekableIterator :: seek ()

If I want to implement seek () to complete the SeekableIterator interface, should I go back to the old position if the position I was looking for is invalid? Like this:

public function seek( $position )
{
    $oldPosition = $this->_position;
    $this->_position = $position;
    if( !$this->valid() )
    {
        $this->_position = $oldPosition;
        throw new OutOfBoundsException( 'Invalid seek position (' . $position . ')' );
    }
}

      

+2


source to share


2 answers


If you are using the reference version of the interface as a guide, then no, you should not "revert" to the original, even if the set target position is invalid.



+3


source


According to the example code from the SPL documentation , you should still change the position.



0


source







All Articles