Welcome Guest, Not a member yet? Register   Sign In
@$variablename or @$array_name[0] what does @ means???

what is the function of @in @$variable_name ?

[eluser]Colin Williams[/eluser]
I believe it means "ignore errors".

I typically see this when calling functions that a script "hopes" will work (like '$this = @realpath($dir);'). Not sure it's ever a good idea to use, and I imagine all it does is allow someone to be a lazy coder while adhering to internal error level standards. I could be off-base about that.

It's more along the lines of 'suppress' errors.

It's also outrageously slow. If you have to make use of @, then your app is either poorly designed or lives in a very fragile environment with 0 error checking/catching. Smile

[eluser]Matthieu Fauveau[/eluser]
Like awpti said, it's very slow.

[eluser]Randy Casburn[/eluser]
Cough... CI has hundreds of these @ error suppressions throughout the entire library for extremely functional reasons. Is CI designed poorly? I think not.

@a123bcd -- at times, some of the PHP functions (file, streams like ftp, some graphics, DB, etc.) primarily focus is returning a handle to a file, or stream or image object or the like. If there is an error or warning they activate the internal PHP warning or error system with the standard warning or error codes. For instance if a file cannot be found, the fopen() function fires an error code E_WARNING but "returns" false.

So if you have your PHP configuration set to display warnings and errors, your most beautiful application just got an PHP warning message blasted all over it. Maybe you've seen this happen before.

So to answer your question, the @ symbol is the only PHP tool available to control the unwanted output of PHP warnings and errors that destroy our pages when we don't want them to.

This tool is used for many reasons. For instance, sometimes it is used to ENHANCE your design. For instance, let's take the fopen() example from above. Now that we've suppressed the nasty looking, uncontrolled PHP warning message, we can actually format our own message, place it in our beautiful application page anywhere we want, make it look real nice, and place the error on the page simply by using this variable $php_errormsg (assuming PHP error reporting is set up correctly -- read the docs).

I hope this is helpful,


[eluser]Colin Williams[/eluser]
Makes sense, Randy. Good to know!

[eluser]Matthieu Fauveau[/eluser]
CI having a lot of these @ doesn't mean it's poorly designed of course. But it doesn't mean it's good coding either.
An application in production shouldn't display any PHP errors to the end user anyways. All in all you are not obligated to use @ at all.

I've never use this and my user never seen any warning or error messages.
I don't know whether we should use this or not but yes I don't like slowness.

Theme © iAndrew 2016 - Forum software by © MyBB