php @ 函数调用前的字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2002610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
@ character before a function call
提问by nixie
What is the difference between these two function calls in PHP?
PHP中这两个函数调用有什么区别?
init_get($somevariable);
@init_get($somevariable);
回答by solidgumby
the "@" will silence any php errors your function could raise.
“@”将消除您的函数可能引发的任何 php 错误。
回答by Sampson
It silences errors and warnings. See Error Control Operators.
它使错误和警告静音。请参阅错误控制运算符。
回答by AntonioCS
As already answered the @will stop the error (if any) from showing up.
In terms of performance this is not recommended.
正如已经回答的那样,这@将阻止错误(如果有)出现。
就性能而言,不建议这样做。
What php is doing is:
php 正在做的是:
- reading the error display state
- setting the error display to show no errors
- running your function
- setting the error display to it's previous state
- 读取错误显示状态
- 将错误显示设置为不显示错误
- 运行你的函数
- 将错误显示设置为之前的状态
If you don't want any errors showing up use error_reporting(0);.
如果您不希望出现任何错误,请使用error_reporting(0);.
Or just write bug free code :P
或者只是编写无错误代码:P
回答by George
http://www.faqts.com/knowledge_base/view.phtml/aid/18068/fid/38
http://www.faqts.com/knowledge_base/view.phtml/aid/18068/fid/38
All PHP expressions can be called with the "@" prefix, which turns off error reporting for that particular expression.
所有 PHP 表达式都可以使用“@”前缀调用,这会关闭该特定表达式的错误报告。
回答by Daniel Sorichetti
As everyone said, it stops the output of errors for that particular function. However, this decreases performance greatly since it has to change the error display setting twice. I would recommend NOT ignoring warnings or errors and fixing the code instead.
正如大家所说,它会停止该特定功能的错误输出。但是,这会大大降低性能,因为它必须两次更改错误显示设置。我建议不要忽略警告或错误,而是修复代码。

