Don wrote:

Hi,

Using a a flat text file based calendar script.
Started getting this error after upgrading PHP:

Warning: fread(): Length parameter must be greater than 0

Function it is occurring in is:

function read_str($fp)
   {
   $strlen = $this->bin2dec(fread($fp,4),4);
   return fread($fp, $strlen);
   }

Any ideas?

Thanks,
Don

It's hard to say without knowing what you're trying to do, but it looks like you're first reading a length value from the file, then reading that number of bytes? In which case if the first fread() fails or returns 0, and assuming $this->bin2dec() is doing its job correctly, you might want to skip trying the second fread():

function read_str($fp)
{
    if ($strlen = $this->bin2dec(fread($fp, 4), 4))
    {
        return fread($fp, $strlen);
    }
}

...this will return NULL if there is nothing to read (i.e. the first
fread() returns 0 or false).

Essentially, the error is occurring because fread() doesn't want a 0
in the length argument, but there is no check in the code to ensure
that this doesn't happen. The above is just one way to possibly get
around it.


Hope this helps,

Torben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to