@readfile returns ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
allelopath
Forum Commoner
Posts: 34
Joined: Tue Mar 16, 2004 5:21 am

@readfile returns ?

Post 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?
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

No, it just prevents any error message from printing. ( in my experimenting ;) )
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Post Reply