Page 1 of 2
The @ in @fread??
Posted: Thu Feb 16, 2006 2:09 pm
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
Posted: Thu Feb 16, 2006 2:15 pm
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
Posted: Thu Feb 16, 2006 2:15 pm
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.
Posted: Thu Feb 16, 2006 2:29 pm
by xcom923
thank you so much I needed that info.
Posted: Fri Feb 17, 2006 7:45 am
by duk
its good to supreme undefined index errors

if(@$_POST[''])
Posted: Fri Feb 17, 2006 7:53 am
by John Cartwright
duk wrote:its good to supreme undefined index errors

if(@$_POST[''])
No its not, thats very sloppy..
empty(),
array_key_exists()
Posted: Fri Feb 17, 2006 7:54 am
by s.dot
duk wrote:its good to supreme undefined index errors

if(@$_POST[''])
try if(isset($_POST['']))

Posted: Fri Feb 17, 2006 7:56 am
by duk
when i use if isset, works but it doesnt check if its empty... and i need to double check the $_POST[''] var...
Posted: Fri Feb 17, 2006 7:57 am
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...
??
Posted: Fri Feb 17, 2006 8:00 am
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']) ) {
Posted: Fri Feb 17, 2006 8:03 am
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
Posted: Fri Feb 17, 2006 8:06 am
by s.dot
really?
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?
Posted: Fri Feb 17, 2006 8:07 am
by John Cartwright
yea
Posted: Fri Feb 17, 2006 8:08 am
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...
Posted: Fri Feb 17, 2006 8:10 am
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