【问题标题】:PHP: SeekableIterator::seek()PHP: SeekableIterator::seek()
【发布时间】:2009-09-07 00:10:44
【问题描述】:

如果我想实现 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 . ')' );
    }
}

【问题讨论】:

    标签: php seek seekableiterator


    【解决方案1】:

    如果您使用 php.net interface reference's example implementation 作为指导方针,那么不,您不应该“恢复”到原始位置,即使提供的目标位置无效。

    【讨论】:

      【解决方案2】:

      根据sample code from the SPL documentation,你还是应该换个位置。

      【讨论】:

      • 我知道我们有同样的想法。 ;)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      • 2015-10-28
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多