|
Posted by gp on 10/17/06 13:44
i am implementing Iterator in a class, I have pretty much copied the
code from php.net on Object Iteration. Adding all the normal methods
for the task...rewind, current, next, etc.
I was attempting to add a seek method but am stymied by the above
warnin, as well getting a seek on index 0 (zero) to work.
public function __construct($contents) {
if ( is_array($contents)) {
if ( is_array($contents[1])) {
$this->cktl = $contents[1];
}
}
}
public function rewind() {
$cktl = rewind($this->cktl);
return $cktl;
}
public function current() {
$cktl = current($this->cktl);
return $cktl;
}
public function key() {
$cktl = key($this->cktl);
return $cktl;
}
public function next() {
$cktl = next($this->cktl);
return $cktl;
}
public function valid() {
$cktl = $this->current() !== FALSE;
return $cktl;
}
public function myseek($intPos) {
$myPos = 0;
$this->rewind();
while ( $myPos < $intPos && $this->valid() ) {
$cktl = $this->next();
$myPos++;
}
if ( !$this->valid() ) {
die("Invalid seek position");
}
return $cktl;
}
Navigation:
[Reply to this message]
|