From: adam at trachtenberg dot com
Operating system: *
PHP version: 5CVS-2004-01-26 (dev)
PHP Bug Type: Unknown/Other Function
Bug description: SPL: SeekableIterator seek() broken
Description:
------------
When a class implements SeekableIterator and provides a
seek() method, SPL does not seek correctly. When SPL is
forced to emulate seek() by advancing step-by-step, it
works correctly. (See NumericArrayIterator vs
SeekableNumericArrayIterator.)
At first, I thought spl_limit_it_seek() needed to call:
if (spl_dual_it_has_more(intern TSRMLS_CC) == SUCCESS) {
spl_dual_it_fetch(intern, 1 TSRMLS_CC);
}
Even for instances of SeekableIterator, but that only
worked with the offset was 0.
Reproduce code:
---------------
class NumericArrayIterator implements Iterator {
protected $a;
protected $i;
public function __construct($a) {
$this->a = $a;
}
public function rewind() {
$this->i = 0;
}
public function hasMore() {
return $this->i < count($this->a);
}
public function key() {
return $this->i;
}
public function current() {
return $this->a[$this->i];
}
public function next() {
$this->i++;
}
}
class SeekableNumericArrayIterator extends NumericArrayIterator implements
SeekableIterator {
public function seek($index) {
if ($index < count($this->a)) {
$this->i = $index;
}
}
}
$a = array(1, 2, 3, 4, 5);
foreach (new LimitIterator(new NumericArrayIterator($a), 0, -1) as $v) {
print "$v\n";
}
foreach (new LimitIterator(new SeekableNumericArrayIterator($a), 0, -1) as
$v) {
print "$v\n";
}
Expected result:
----------------
1
2
3
4
5
1
2
3
4
5
Actual result:
--------------
1
2
3
4
5
--
Edit bug report at http://bugs.php.net/?id=27042&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27042&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27042&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27042&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27042&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27042&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27042&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27042&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27042&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27042&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27042&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27042&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27042&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27042&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27042&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27042&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27042&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27042&r=float