PHP @?

Associate
Joined
26 Jun 2003
Posts
1,140
Location
North West
Ive seen code where people precede functions with @, such as:

@mysql_query(...);

Whats the difference between using @ and without @?

Thx
 
Well I havent done any PHP for about the last 3 years but I seem to remember it supresses error messages to the screen. I.e. if there is an error with your database connection the user won't see it.
 
JonD said:
Ive seen code where people precede functions with @, such as:

@mysql_query(...);

Whats the difference between using @ and without @?

Thx

Keeps an error showing from that particular section of coding.
 
Exactly. Not ideal to use really...database queries are normally quite important in the structure of a page, so should really be treated with the die function instead of supressing the error.

You should only really use surpressing in for example, cron jobs where it is highly likely that something may fail like getting the contents of the file. If there is an error, this would then be emailed by crontab or whatever you use to your account. A bit of a pain if the cron job is used reguarly.

In theory, if you structure your code properly and think of all the things that could go wrong in your script, you should never have to surpress error messages to the user.
 
suppressing is ideally only acceptable in places where you have your own error handling.

The likes of methods that throw exceptions, where a function would normally generate a warning (readfile(), or opendir() for example)
 
Back
Top Bottom