What does @ do?
Moderator: General Moderators
What does @ do?
I have seen @ used before functions and a few other things I think. What does it do?
Re: What does @ do?
If a function fails to exec, @ prevents the error message to be displayed.One armed space goat wrote:I have seen @ used before functions and a few other things I think. What does it do?
-
vincenzobar
- Forum Commoner
- Posts: 95
- Joined: Wed Nov 02, 2005 9:57 am
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.
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?
It hangs around waiting for people to discover it and abuse it's functionality.One armed space goat wrote:What does it do?
It can be useful, but it's also probably one of the most mistreated operators within PHP
Re: What does @ do?
What is its proper use then? and how do people use it inproperly? What could I do with this?redmonkey wrote:It hangs around waiting for people to discover it and abuse it's functionality.One armed space goat wrote:What does it do?
It can be useful, but it's also probably one of the most mistreated operators within PHP
Re: What does @ do?
I would like to know that too.One armed space goat wrote:What is its proper use then? and how do people use it inproperly? What could I do with this?redmonkey wrote:It hangs around waiting for people to discover it and abuse it's functionality.One armed space goat wrote:What does it do?
It can be useful, but it's also probably one of the most mistreated operators within PHP
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...
Another quite useful one is including of files...
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]
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
}Code: Select all
$loaded = @include('somefile.php');
if (!$loaded)
{
// throw some error
}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]
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.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.
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.
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.
So, using @getimagesize() will supress my error log from being overloaded with these errors.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
now here's the real question:
what does it mean in a sample like this?
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.Burrito wrote:now here's the real question:
what does it mean in a sample like this?
Code: Select all
function @ myFunction() { // some stuff }
probably....redmonkey wrote:It means you'll have a parse error in your code.Burrito wrote:now here's the real question:
what does it mean in a sample like this?
Code: Select all
function @ myFunction() { // some stuff }