diff options
author | Marcus Boerger <helly@php.net> | 2003-06-22 12:57:53 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2003-06-22 12:57:53 +0000 |
commit | f4d3111e8a72736f28955d61c6924900d951d787 (patch) | |
tree | 80f08a51ca415f34dccfc470ce8cce3812c0c6a6 | |
parent | b5434aac368a536d25cd87bf98af4ccdd3135a09 (diff) | |
download | php-git-f4d3111e8a72736f28955d61c6924900d951d787.tar.gz |
Fix example
-rwxr-xr-x | ext/spl/examples/dba_dump.php | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/ext/spl/examples/dba_dump.php b/ext/spl/examples/dba_dump.php index d32f1761c9..0481d15a92 100755 --- a/ext/spl/examples/dba_dump.php +++ b/ext/spl/examples/dba_dump.php @@ -5,54 +5,48 @@ * Usage php dba_dump <file> <handler> * * Note: configure with --enable-dba + * + * (c) Marcus Boerger */ -class dba_reader implements spl::iterator { +class dba_reader implements spl_sequence_assoc +{ - public $db = NULL; + private $db = NULL; + private $key = false; + private $val = false; function __construct($file, $handler) { $this->db = dba_open($file, 'r', $handler); } - function new_iterator() { - return new dba_iter($this); - } - function __destruct() { if ($this->db) { dba_close($this->db); } } -} - -class dba_iter implements spl::sequence_assoc { - - private $obj; - private $key = NULL; - private $val = NULL; - function __construct($obj) { - $this->obj = $obj; - } - - function reset() { - if ($this->obj->db) { - $this->key = dba_firstkey($this->obj->db); + function rewind() { + if ($this->db) { + $this->key = dba_firstkey($this->db); } } - function elem() { + function current() { return $this->val; } function next() { - $this->key = dba_nextkey($this->obj->db); + if ($this->db) { + $this->key = dba_nextkey($this->db); + if ($this->key !== false) { + $this->val = dba_fetch($this->key, $this->db); + } + } } - function more() { - if ($this->obj->db && $this->key !== false) { - $this->val = dba_fetch($this->key, $this->obj->db); + function has_more() { + if ($this->db && $this->key !== false) { return true; } else { return false; |