Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@readfile returns ?

Status
Not open for further replies.

omom

Programmer
Joined
Apr 21, 2004
Messages
3
Location
US
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?

 
Possibly.

In general, though, I strongly recommend against ever using the "@" error-suppression operator. It is much better to write code that reacts gracefully to errors rather than simply ignoring them.

Instead of:
Code:
$foo = @readfile('somefile.txt');

the following would be better:
Code:
if ([url=http://us2.php.net/manual/en/function.file-exists.php]file_exists[/url]('somefile.txt'))
{
   $foo = readfile ('somefile.txt');
}
else
{
   //perform graceful error-handling here
}



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
thanks, didn't know about file_exists()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top