]> granicus.if.org Git - php/commitdiff
Fix example
authorMarcus Boerger <helly@php.net>
Sun, 22 Jun 2003 12:57:53 +0000 (12:57 +0000)
committerMarcus Boerger <helly@php.net>
Sun, 22 Jun 2003 12:57:53 +0000 (12:57 +0000)
ext/spl/examples/dba_dump.php

index d32f1761c9398568018510122f8b17f1ed54b0bd..0481d15a9283db450aed9fec3fca41e83960784c 100755 (executable)
@@ -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;