what is @?

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
kanec
Forum Newbie
Posts: 7
Joined: Thu Jun 28, 2007 4:13 am

what is @?

Post by kanec »

i see '@' being used sometimes.
when and why should i use it?

xamp:
"if(!$dh = @opendir($dir)) return;"
User avatar
TheMoose
Forum Contributor
Posts: 351
Joined: Tue May 23, 2006 10:42 am

Post by TheMoose »

It tells the PHP engine to hide any error output that might normally occur.

IE:
If opendir($dir) failed due to an error, you wouldn't know because the @ symbols hides the error reporting.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

It suppresses error messages and you really shouldn't use it. The only time you'll need it is if there's an error message that may be displayed on a public website because you have error_reporting on a live site for some reason, and you want to handle the error without it showing on the page.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

The @ operator is also called the "shut-up" error. What it does is temporarily set error_reporting to 0. It's not very portable (if a custom error handler does not honor error_reporting, it will have no effect), so I'd avoid it.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

I use it to make custom error messages.
Here is an example where message is a function that displays the error message:

Code: Select all

$handle = @opendir($dir) or message(__FILE__, __LINE__, 'error', '<strong>Can\'t open directory:</strong><br>' . htmlentities($dir) . '<ul class="compact"><li>Check media_dir value in config.inc.php</li><li>Check file/directory permission</li></ul>');
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

@ is a little performance degrading monster that should rarely, if ever be used.
Post Reply