Page 1 of 1

@readfile returns ?

Posted: Wed Apr 21, 2004 11:04 am
by allelopath
I'm trying to understand what exactly @readfile() does (as opposed to readfile() ). According to the docs, using @ in front prevents an error message from printing:

"
Returns the number of bytes read from the file. If an error occurs, FALSE is returned and unless the function was called as @readfile(), an error message is printed.
"

In my experimenting it appears to do more than that. It appears to prevent any value being returned. Is this correct?

Posted: Wed Apr 21, 2004 11:13 am
by mudkicker
No, it just prevents any error message from printing. ( in my experimenting ;) )

Posted: Wed Apr 21, 2004 11:54 am
by JAM

Code: Select all

$tmp = readfile('foo.bar'); // existing file
    echo "\n tmp is now $tmp \n";
You are both right. With or without the @ the $tmp above will result in # of bytes of foo.bar. If foo.bar does not exist, $tmp will not be set, and an error is produced, hence using @ can be used to simply remove the error notice.

Not "a good thing" (tm) to do at all times, so do not use it everywhere.