PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
class DOMIterator implements RecursiveIterator
{
protected $node;
protected $index = 0;
public function __construct(DOMNode $node) {
$this->node = $node;
}
public function key() {
return $this->index;
}
public function current() {var_dump($this);
if (!$this->valid()) return false;
return $this->node->childNodes->item($this->index);
}
public function next() {
if ($this->valid()) {
return $this->node->childNodes->item(++$this->index);
} else {
return false;
}
}
public function rewind() {
$this->index = 0;
if ($this->valid()) return false;
else return $this->current();
}
public function valid() {
return $this->node->childNodes->length > $this->index;
}
public function hasChildren() {
return (bool) $this->node->childNodes->length;
}
public function getChildren() {
return new DOMIterator($this->current());
}
}