class alt_iterator {
private $st = array();
function next() { ... }
function current() { ... }
function valid() { ... }
//... put the rest here
function protocol() {
return array(
array($this,'next'),
array($this,'current'),
array($this,'valid'),
.....
);
}
}
//an example use: iterator protocol
function do_them($itor, $callback ) {
list($next, $current, $valid, ...) = $itor->protocol();
while($valid) {
$callback( $current );
$next();
}
}