As I said in the previous segment, it’s mandatory to implement within the “MySQLi_ResultWrapper” class the rest of the methods declared by the Iterator interface. In reality, this process is pretty straightforward, and the code fragment below will hopefully demonstrate my point: // get current result set pointer (implementation required by 'key()' method in Iterator interface) public function key() { return $this->_pointer; }
// move forward result set pointer (implementation required by 'next()' method in Iterator interface) public function next() { ++$this->_pointer; $this->movePointer($this->_pointer); return $this; }
// determine if result set pointer is valid or not (implementation required by 'valid()' method in Iterator interface) public function valid() { return $this->_pointer < $this->num_rows; }
Didn’t I tell you that the implementation of the remaining methods declared by the Iterator interface was going to be easy to understand? Well, the code sample above should reaffirm this concept, since now those methods give the “MySQLi_ResultWrapper” class an API that permits us to traverse database result sets as if they were regular arrays, aside from allowing the internal pointer to move back and forth. So far, so good. Now that the methods have a shiny new implementation, it’s time to show the full source code of the “MySQLi_ResultWrapper” class, so you can see how it looks after adding the methods to it. This will be done in the following segment, so click on the link shown below and read the following lines.
blog comments powered by Disqus |
|
|
|
|
|
|
|