ID:               27042
 Updated by:       [EMAIL PROTECTED]
 Reported By:      adam at trachtenberg dot com
-Status:           Open
+Status:           Closed
 Bug Type:         Zend Engine 2 problem
 Operating System: *
 PHP Version:      5CVS-2004-01-26 (dev)
 Assigned To:      helly
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2004-01-26 02:16:51] adam at trachtenberg dot com

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 this bug report at http://bugs.php.net/?id=27042&edit=1

Reply via email to