The @ in @fread??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

The @ in @fread??

Post by xcom923 »

I was looking at some code and I was wondering what the @ sign does in front of a function. the example I saw was @fread
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

error suppression operator. It's recommended not to use it, unless you know exactly what you're doing.

http://php.net/language.operators.errorcontrol
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

It supresses any error that the function may spit out.. I generally wouldn't recommend its use as it may hide important errors that have occured.
xcom923
Forum Newbie
Posts: 22
Joined: Wed Feb 08, 2006 7:21 pm

Post by xcom923 »

thank you so much I needed that info.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

its good to supreme undefined index errors :) if(@$_POST[''])
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

duk wrote:its good to supreme undefined index errors :) if(@$_POST[''])
No its not, thats very sloppy.. empty(), array_key_exists()
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

duk wrote:its good to supreme undefined index errors :) if(@$_POST[''])
try if(isset($_POST[''])) ;)
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.
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

when i use if isset, works but it doesnt check if its empty... and i need to double check the $_POST[''] var...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Jcart wrote:
duk wrote:its good to supreme undefined index errors :) if(@$_POST[''])
No its not, thats very sloppy.. empty(), array_key_exists()
duk wrote:when i use if isset, works but it doesnt check if its empty... and i need to double check the $_POST[''] var...
??
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

if(isset($_POST['var']) // will return true if isset...

but if its empty $_POST['var'] isset() will not check...

i have to do if((isset($_POST['var'])) && ($_POST['var']) ) {
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I'm afraid thats incorrect,

Code: Select all

$var = '';
var_dump(isset($var));
//returns bool(true)
use empty()

i have to do if((isset($_POST['var'])) && ($_POST['var']) ) {
could be condensed to

Code: Select all

if (!empty($_POST['var'])) {
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

really?

Code: Select all

if(!empty($_POST['var']))
is the same as

Code: Select all

if(isset($_POST['var']) && !empty($_POST['var']))
As in.. the first example won't emit a notice error?
Or is the second example redundant?
Last edited by s.dot on Fri Feb 17, 2006 8:07 am, edited 1 time in total.
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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

yea
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

ok what im saying is that isset will return true in the case the var is SET and return true if is empty or not in case is SET...

but in that case i would use:

Code: Select all

if ( (isset($_POST['var']) ) && (!empty($_POST['var'])) {

code

}
but if a change for this:

Code: Select all

// will do the same and much better to write 
if( @$_POST['']) {

code

}
but i dont know if is total correct...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

it will do the same
so i guess if you know why you're using the @ then it's ok

the only instance I recall using @ was when including a file that had session_start() on it, when it may or may not have been already called

so to avoid a notice I put @session_start
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.
Post Reply