mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
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:
parent
12c69dff68
commit
0851a6f64a
1 changed files with 6 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue