From f4d3111e8a72736f28955d61c6924900d951d787 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 22 Jun 2003 12:57:53 +0000 Subject: [PATCH] Fix example --- ext/spl/examples/dba_dump.php | 44 +++++++++++++++-------------------- 1 file 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 * * 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; -- 2.40.0