Page 1 of 1

what is @?

Posted: Wed Jul 18, 2007 2:00 pm
by kanec
i see '@' being used sometimes.
when and why should i use it?

xamp:
"if(!$dh = @opendir($dir)) return;"

Posted: Wed Jul 18, 2007 2:02 pm
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.

Posted: Wed Jul 18, 2007 2:03 pm
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.

Posted: Wed Jul 18, 2007 3:49 pm
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.

Posted: Thu Jul 19, 2007 12:53 am
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>');

Posted: Thu Jul 19, 2007 12:56 am
by Benjamin
@ is a little performance degrading monster that should rarely, if ever be used.