View Full Version : @ before functions or variable in PHP


nacho
09-09-2005, 07:27 AM
Hi!
I have seen in some PHP codes an @ before some sentences.
Example:
@mysql_query("select ...")

I don't what it means, since I have always programmed without using @.

Does any know the difference between putting and not putting the @?

Thanks in advance.

sarahk
09-10-2005, 02:33 AM
It means supress errors.

It used to be recommended but I'd prefer to put in proper error handling rather than rely on @

Atomical
10-13-2005, 10:09 AM
Use an error handler to log the errors to disk. The @ sign is designed for fopen(). If you create a file that doesn't exist fopen will usually give you an error. Some people put the @ sign in front of mysql query but they check the value. It prevents users from seeing what the query was or how it failed.

if ( @mysql_query("ABC") ) {

} else {

//log

}

RyanSmith
10-19-2005, 07:21 PM
I agree, it's better to just handle your errors properly. I'll admit that I love try catch blocks, but programming purests will tell you that you should never have to use a try catch if you write your code properly.

The @ supressor tends to breed sloppy programming in my opinion, but that might be because I have had a bunch of Computer Science BS shoved down my throat.

sarahk
10-19-2005, 07:26 PM
That said I was mucking about with AJAX (http://sarahk.pcpropertymanager.com/blog/ajax-finally/204/) the other day and the javascript try catch is good for testing a users browser capabilities.

RyanSmith
10-19-2005, 08:35 PM
That's the way I have seen it done in almost every AJAX example too. JavaScript tends to be a very loose language to work with. In some whys that's good, and in some ways you can really get yourself into trouble.

Atomical
10-22-2005, 01:02 PM
Have you guys checked out sajax?

RyanSmith
10-22-2005, 04:07 PM
Ya, SAJAX is a sweet little piece of code. I haven't worked with it too much yet, but I"m planning on creating a whole new site dedicated to AJAX. I'll probably end up using SAJAX for quite a bit of it.

Atomical
10-25-2005, 09:57 AM
Before I got sidetracked I was working on an ajax forum.