2

I am a newbie in PHP.

I do not know the meaning of @, for example:

$key = @$_REQUEST['key'];

I have searched in google but can not find anything.

Some help me! Please !

5 Answers5

4

The @ symbol tells the function to fail silently instead of dumping some sort of error message. It is listed under error control operators in the PHP manual.

Matt Wonlaw
  • 12,146
  • 5
  • 42
  • 44
2

It suppresses any errors that the line would normally produce. In this case if the key doesn't exist, an error will occur but the error text will be silenced.

Chris Eberle
  • 47,994
  • 12
  • 82
  • 119
1

It suppresses errors and warnings.

spanky
  • 1,479
  • 2
  • 11
  • 22
1

You've found the error control operator!

Matt Stephenson
  • 8,442
  • 1
  • 19
  • 19
1

It suppresses warnings in PHP. In that example it could be used to suppress and undefined index warning, if $_REQUEST['key'] doesn't exist. It's usually better practice to write:

$key = isset($_REQUEST['key']) ? $_REQUEST['key'] : 'default value for key here';
Paul
  • 139,544
  • 27
  • 275
  • 264