Fixed example code: __construct() is not required by SeekableIterator interface, an Iterator must not automatically rewind, A SeekableIterator should not set its position out of bounds

-- 
Provided by ha kre (hanskrentel@yahoo.de)

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@330180 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Peter Cowburn 2013-05-07 07:13:05 +00:00
parent 12c69dff68
commit 0851a6f64a

View file

@ -59,7 +59,7 @@
<?php
class MySeekableIterator implements SeekableIterator {
private $position = 0;
private $position;
private $array = array(
"first element",
@ -68,20 +68,18 @@ class MySeekableIterator implements SeekableIterator {
"fourth element"
);
/* Method required for SeekableIterator interface */
public function seek($position) {
$this->position = $position;
if (!$this->valid()) {
if (!isset($this->array[$position]) {
throw new OutOfBoundsException("invalid seek position ($position)");
}
$this->position = $position;
}
/* Methods required for Iterator interface */
public function __construct() {
$this->position = 0;
}
public function rewind() {
$this->position = 0;
}