"@" in front of a function

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
methos
Forum Newbie
Posts: 13
Joined: Sat Oct 21, 2006 8:31 am

"@" in front of a function

Post by methos »

What does the "@" sign do in front of a function?

What's the difference between @unlink and unlink?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

@ suppresses error messages, so if unlink gave an error (e.g. path does not exist, or not permission to delete) the @unlink would tell PHP not to display the error. In general it is considered bad form to use @ because if you expect that a error could occur then you should do proper checks for the error conditions. For example:

Code: Select all

if (file_exists($fileame) && is_writable($filename)) {
     unlink($filename);
}
Last edited by Christopher on Mon Jan 08, 2007 5:02 pm, edited 1 time in total.
(#10850)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Post Reply