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
  • 2,029
  • 4
  • 22
  • 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
  • 46,743
  • 31
  • 106
  • 145
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
  • 80,671
  • 25
  • 200
  • 267
1

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

Jon
  • 428,835
  • 81
  • 738
  • 806
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,536
  • 6
  • 41
  • 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,823
  • 5
  • 60
  • 78