4

i wonder what does @ means when we use it before include or require in php ?!

such as :

@include('block.php');

maybe its a noob question , but i need to know it guys ?!

so sorry for that

VolkerK
  • 95,432
  • 20
  • 163
  • 226
Mac Taylor
  • 5,020
  • 14
  • 50
  • 73
  • see e.g. http://stackoverflow.com/questions/1032161/what-is-the-use-of-symbol-in-php and http://stackoverflow.com/questions/138159/php-alias-function – VolkerK Apr 26 '10 at 23:23

3 Answers3

10

@ is the shut-up operator. If something goes wrong, no error message will be shown. It's usually a bad practice to use it; first because error messages happen for a good reason, and second because it's ridiculously slow for what it does.

It's roughly equivalent to wrapping the statement in:

$oldErrorLevel = error_reporting(0);
// the statement
error_reporting($oldErrorLevel);

Here's the link to the PHP manual page documenting it.

zneak
  • 134,922
  • 42
  • 253
  • 328
3

@ before a function call suppresses any errors that function would normally output.

In the case of include, the person doing that wants the script to keep going if block.php isn't present. A better way of doing this is usually to do something like this instead:

if(is_readable('block.php')) {
  include('block.php');
}
ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • 3
    There are other reasons that can prevent a file from loading though, like permissions. – zneak Apr 26 '10 at 21:53
0

@ is the error supression operator in php, you won't see any error if the file is not found in that statement.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578