PDA

View Full Version : PHP's @ function


duniyadnd
08-12-2003, 07:52 AM
Most people know about the "@" in Php, which is an exception for all errors. I tend to avoid using such exceptions, as I won't know if the program runs properly or not. Just want to know everyone else's opinion on how often they use it or don't use it.

raf
08-12-2003, 08:13 AM
I use it a lott and i always include a ' or die ("My customerror") ' clause for these functions. It gives you the opportunity to display customized errors that only 'leak' the info you want to display to the client + you still trap all error

So i completely disagree with this
I tend to avoid using such exceptions, as I won't know if the program runs properly or not.

If used correctly (--> supplying your own errormessage), then its safer and more userfriendly, without any disadvantages (well, you need to type in the errormessages of course, but that's mainly copy - paste (since it are almost always the same functions like db-connections and querys etc) or you could include them and have a central errormessage document with all the errormessages in 1 array)

mordred
08-12-2003, 10:31 AM
I almost never use the @ operator, so I basically agree with you, duniyadnd. Only in my custom error handling object I use it because throwing an error within an error handler could lead to interesting circular dependencies... ;)

raf, what you say is correct, but putting out customized error messages with die() is IMO also quite limited. For instance, you can't call methods in die(). So if you want to log the error messages, you need a different mechanism. Further, die() can stop your script at a stage which may leave your objects in an incomplete state. That's undesirable.

Personally I either use trigger_error() with a custom error handler or a singleton-like method of an error object. This leaves you more room to deal with errors depending on their severity.

Though for testing/developing die() is very useful to track down the exact location of an error, particularly in complex architectures.