Page 1 of 2
What does @ do?
Posted: Wed Nov 09, 2005 12:08 pm
by Luke
I have seen @ used before functions and a few other things I think. What does it do?
Re: What does @ do?
Posted: Wed Nov 09, 2005 12:12 pm
by conthox
One armed space goat wrote:I have seen @ used before functions and a few other things I think. What does it do?
If a function fails to exec, @ prevents the error message to be displayed.
Posted: Wed Nov 09, 2005 12:12 pm
by vincenzobar
Mysql functions it suppresses the built in error codes
like @mysql_query
can be used in a IF statement to print your own errors
Posted: Wed Nov 09, 2005 12:19 pm
by Jenk
It surpresses PHP's Exception error messages for the command it is preceding.
I can't find the page for it atm, but it only supresses non-fatal errors (E_WARNING and E_NOTICE errors and E_STRICT in PHP5), if it is E_CORE_*, E_COMPILE_*, E_ERROR or E_PARSE error (all fatal errors), then you will still see an error message.
Re: What does @ do?
Posted: Wed Nov 09, 2005 12:33 pm
by redmonkey
One armed space goat wrote:What does it do?
It hangs around waiting for people to discover it and abuse it's functionality.
It can be useful, but it's also probably one of the most mistreated operators within PHP
Re: What does @ do?
Posted: Wed Nov 09, 2005 12:36 pm
by Luke
redmonkey wrote:One armed space goat wrote:What does it do?
It hangs around waiting for people to discover it and abuse it's functionality.
It can be useful, but it's also probably one of the most mistreated operators within PHP
What is its proper use then? and how do people use it inproperly? What could I do with this?
Re: What does @ do?
Posted: Wed Nov 09, 2005 12:41 pm
by conthox
One armed space goat wrote:redmonkey wrote:One armed space goat wrote:What does it do?
It hangs around waiting for people to discover it and abuse it's functionality.
It can be useful, but it's also probably one of the most mistreated operators within PHP
What is its proper use then? and how do people use it inproperly? What could I do with this?
I would like to know that too.
Posted: Wed Nov 09, 2005 12:49 pm
by redmonkey
It is as mentioned previously, it is used for error supression, the problem that I have noted with it is that many people seem to discover it, then start applying it to every error the come across rather than attempting to resolve the error at the root of the problem. This leaves them wondering why A) their script doesn't work and B) why they aren't seeing any error messages.
I do use it myself, but very rarely do I have cause to use it without and additional error trap. Some classic uses are...
A simple database connection...
Code: Select all
$conn_id = @mysql_connect('blah', 'blah', 'blah');
if (!$conn_id)
{
//throw some error
}
Another quite useful one is including of files...
Code: Select all
$loaded = @include('somefile.php');
if (!$loaded)
{
// throw some error
}
That one there is quite handy as normally if include fails script execution continues and an error is generated. If you need/want script execution to halt if the file does not get included then you have two options. Do as above and you can gracefully fall over, or use require which terminates script execution with and ugly warning thrown out to the buffer.
There are many uses for it and it if used properly is extremly useful.
[EDIT] I have also noted that my motor skills appear to be failing tonight, apologies for the numerous typos and missing words.[/EDIT]
Posted: Wed Nov 09, 2005 1:02 pm
by Roja
redmonkey wrote:I have noted with it is that many people seem to discover it, then start applying it to every error the come across rather than attempting to resolve the error at the root of the problem.
That is an absolutely perfect description of the situation. I have the same issue with html designers and html compliance, and the list expands from there.
Excellent description.
A good "where would I use it properly" example would be a place where I knew I would throw an error, but I disagreed with the parser. The only actual time I've encountered it, and felt justified/correct in using it was in adodb in a very specific combination involving the xml parser, which isn't properly maintained.
Its definitely a rare thing for me to use it without an intention of removing it very soon after using it.
Posted: Wed Nov 09, 2005 1:58 pm
by s.dot
A good example of its use is in forums. For example, resizing pictures that are coming from your forum users. Whos to say that their picture is actually a valid url? When getting the size of that image, if PHP can't find the image, it will produce an hour.
So, using @getimagesize() will supress my error log from being overloaded with these errors.

Posted: Wed Nov 09, 2005 2:28 pm
by Luke
Great... you guys are awesome... thanks for the examples.
Posted: Wed Nov 09, 2005 8:06 pm
by Jenk
one function I always use it on is mysql_close().
Posted: Wed Nov 09, 2005 9:14 pm
by Burrito
now here's the real question:
what does it mean in a sample like this?
Code: Select all
function @ myFunction()
{
// some stuff
}
Posted: Wed Nov 09, 2005 9:21 pm
by redmonkey
Burrito wrote:now here's the real question:
what does it mean in a sample like this?
Code: Select all
function @ myFunction()
{
// some stuff
}
It means you'll have a parse error in your code.
Posted: Wed Nov 09, 2005 9:48 pm
by Burrito
redmonkey wrote:Burrito wrote:now here's the real question:
what does it mean in a sample like this?
Code: Select all
function @ myFunction()
{
// some stuff
}
It means you'll have a parse error in your code.
probably....
