What does @ mean before a variable? [duplicate]
Possible Duplicate:
Reference - What does this symbol mean in PHP?
I have this assignment:
$buffer=@data_value[$i];
what does the @ mean?
That prevents any warnings or errors from being thrown when accessing the i
th element of data_value
.
See this post for details.
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];
It is called the "error-control operator". Since it's an assignment, I believe you should do the rest yourself.
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;
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.
精彩评论