我应该在 PHP 中使用 @ 来发出警告吗?
例如,删除时PHP 中的一个文件。 @unlink($文件);或取消链接($file);
我听说过关于使用@的不好的事情。有人可以解释为什么我们应该或不应该使用它吗?
Possible Duplicates:
Reference - What does this symbol mean in PHP?
Should I use @ in my PHP code?
For example, when deleting a file in PHP. @unlink($file); or unlink($file);
I've heard bad things about using @. Can someone explain why we should or shouldn't use this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@ 符号可以抑制任何错误。如果您的脚本在上面的示例中无法
unlink()
,您将不会看到任何有关它的错误输出。您可以自行决定是否使用它来消除错误。不过,就我个人而言,我尽量避免使用它,因为我想知道是否有任何错误。The @ symbol suppresses any errors. If your script is failing to
unlink()
in your example above, you wouldn't see any error output about it. Its use is at your discretion for bug squashing or not. Though, personally I try to avoid its use because I want to know about any errors.如果你用它来做某事,操作成功与否并不重要。如果您需要从安全数据库中删除某人,您可能不希望抑制来自该脚本的警告。
但大多数时候您会希望听到错误和警告,因此在 PHP 中有限地使用它是最好的,但很少有时候它会派上用场。
If you use it on something that doesn't matter whether the operation was successful or not. If you needed to delete someone from a secure database, you probably wouldn't want to suppress a warning coming from that script.
But most of the time you'll want to hear the errors and warnings, so limited use of this in PHP is best, but there are the very few times it comes in handy.