You are here: Re: warning: rewind() supplied argument is not a valid stream resource in... « PHP Programming Language « IT news, forums, messages
Re: warning: rewind() supplied argument is not a valid stream resource in...

Posted by Jerry Stuckle on 10/17/06 17:17

gp wrote:
> 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.
<snip>
>
> 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;
> }
>

if $intPos is 0, you never enter your while loop and therefore never
execute your assignment to $cktl. Also, it's unnecessary overhead to
set $cktl each time through the loop. All you really need to do is
advance the pointer.

Try this:

public function myseek($intPos) {
$myPos = 0;
$this->rewind();
while ( $myPos < $intPos && $this->valid() ) {
$this->next();
$myPos++;
}
if ( !$this->valid() ) {
die("Invalid seek position");
}

return $this->current();
}


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация