Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does @ mean in PHP? [duplicate]

Tags:

php

Possible Duplicate:
Reference - What does this symbol mean in 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?

like image 970
FlyingCat Avatar asked Sep 01 '10 18:09

FlyingCat


2 Answers

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

For instance, using:

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

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"); 

would not.

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.

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

like image 68
Frxstrem Avatar answered Sep 22 '22 02:09

Frxstrem


The @ sign tells PHP to ignore error messages.

PHP Error Control Operators

like image 34
Rocket Hazmat Avatar answered Sep 20 '22 02:09

Rocket Hazmat