@在PHP中是什么意思? [英] What does @ mean in PHP?

查看:151
本文介绍了@在PHP中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
参考-此符号在PHP中是什么意思?

Possible Duplicate:
Reference - What does this symbol mean in PHP?

我想知道@在PHP语言中的含义.我见过有人在使用

I was wondering what @ means in PHP language. I have seen people using

$connect = @mysql_query('sql query here');

不知道为什么.有人可以帮我解释一下吗?

Not sure why. Could someone explain it for me?

推荐答案

@运算符告诉PHP禁止显示错误消息,这样就不会显示错误消息.

The @ operator tells PHP to suppress error messages, so that they will not be shown.

例如,使用:

$result = mysql_query("this is an invalid query");

会导致显示警告,告诉您MySQL查询无效,而

would result in a warning being shown, telling you that the MySQL query is invalid, while

$result = @mysql_query("this is still an invalid query");

不会.

但是,请注意,这是非常糟糕的编程习惯,因为它不会使错误消失,而只是将它们隐藏起来,并且使调试变得更加糟糕,因为您看不到代码的实际问题.

Note, however, that this is very bad programming practice as it does not make error disappear, it just hides them, and it makes debugging a heck of a lot worse since you can't see what's actually wrong with your code.

您应该禁用>而不是@,而仅display_errors禁用 error_reportingdisplay_errors /errorfunc.configuration.php"rel =" noreferrer> php.ini

Instead of using @, you should disable error_reporting and display_errors just display_errors in php.ini

这篇关于@在PHP中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆