Hannes Magnusson wrote:
Hi Giunta

On 5/28/07, Gaetano Giunta <[EMAIL PROTECTED]> wrote:
Hello there.

The online manual for fread states clearly "Returns the read string or FALSE
in case of error."
I was always puzzled by that assertion, and today decided to digg into the
code.

As a matter of fact, the only time fread returns FALSE (on php 5) is when it
is invoked whith a negative $length, or with a single parameter.

In PHP4.4 and 5.2 (didn't check HEAD) fread() will return false (and a
warning thrown) if the resource argument isn't a stream resource and
if the the second argument (length) is 0 or less.
NULL will be returned (and warning thrown) if fread() doesn't get
passed two arguments (like most other functions).


Maybe an update would be appropriate?

I don't see anything wrong with them..

Well, the way I understood the manual, I would have expected fread to return FALSE if something outside of the control of the programmer went wrong, ie. something that could happen to the stream while reading from it. Passing a negative lenght or a not-stream resource are errors on the part of the coder - thus if the code path that leads to the fread call checks for a positive length and a valid (opened) stream, checking later for false is completely useless - and relying on it not returning false as sure sign that everything went fine is a possible unintended consequence (ok, maybe a stupid assumption, but it might happen... to dumb people like me ;)

I am not too sure about the best way to phrase it, but "Returns the read string or FALSE when invoked with erroneous parameters" is much more precise.

Bye
Gaetano

Reply via email to