如果我想实现seek()来完成SeekableIterator接口,如果查找的位置无效,我是否应该在内部恢复到旧位置?如下所示:
public function seek( $position )
{
$oldPosition = $this->_position;
$this->_position = $position;
if( !$this->valid() )
{
$this->_position = $oldPosition;
throw new OutOfBoundsException( 'Invalid seek position (' . $position . ')' );
}
}发布于 2009-09-07 00:14:01
如果您使用php.net interface reference's example implementation作为指导,则不应该“恢复”到原始位置,即使提供的目标位置无效。
发布于 2009-09-07 00:14:41
根据sample code from the SPL documentation的说法,你仍然应该改变位置。
https://stackoverflow.com/questions/1387077
复制相似问题