开发者

What does @ mean before a variable? [duplicate]

开发者 https://www.devze.com 2023-01-29 19:45 出处:网络
This question alre开发者_开发知识库ady has answers here: Closed 12 years ago. Possible Duplicate:
This question alre开发者_开发知识库ady has answers here: Closed 12 years ago.

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 ith 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消