4

Possible Duplicate:
Reference - What does this symbol mean in PHP?

I have this assignment:

$buffer=@data_value[$i];

what does the @ mean?

Community
  • 1
  • 1
Matteo
  • 1,999
  • 4
  • 20
  • 30

5 Answers5

8

That prevents any warnings or errors from being thrown when accessing the ith element of data_value.

See this post for details.

Chetan
  • 44,172
  • 28
  • 104
  • 142
5

The @ will suppress errors about variable not being initialized (will evaluate as null instead).

Also, your code is probably missing a $ after @:

$buffer=@$data_value[$i];
rustyx
  • 73,455
  • 21
  • 176
  • 240
1

It is called the "error-control operator". Since it's an assignment, I believe you should do the rest yourself.

Jon
  • 413,451
  • 75
  • 717
  • 787
0

the @ in front of a statement means that no warnings/errors should be reported from the result of that statement. To put simply, Error Reporting is suppressed for this statement.

This is particularly useful, when e.g. @fclose(fopen("file.txt",w")) which can throw several warnings/errors depending on the situation, but with an @ in front of it, all these warnings or errors will be suppressed.

Stoic
  • 10,058
  • 5
  • 40
  • 60
0

As above, it suppresses the error if the array key doesn't exist. A version which will do the same without resorting to dodgy error suppression is

$buffer = array_key_exists($i, $data_value) ? $data_value[$i] : null;
El Yobo
  • 14,464
  • 5
  • 57
  • 77