The @ in @fread??
Moderator: General Moderators
The @ in @fread??
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
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
error suppression operator. It's recommended not to use it, unless you know exactly what you're doing.
http://php.net/language.operators.errorcontrol
http://php.net/language.operators.errorcontrol
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
No its not, thats very sloppy.. empty(), array_key_exists()duk wrote:its good to supreme undefined index errorsif(@$_POST[''])
try if(isset($_POST['']))duk wrote:its good to supreme undefined index errorsif(@$_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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Jcart wrote:No its not, thats very sloppy.. empty(), array_key_exists()duk wrote:its good to supreme undefined index errorsif(@$_POST[''])
??duk wrote:when i use if isset, works but it doesnt check if its empty... and i need to double check the $_POST[''] var...
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I'm afraid thats incorrect,
use empty()
Code: Select all
$var = '';
var_dump(isset($var));
//returns bool(true)could be condensed toi have to do if((isset($_POST['var'])) && ($_POST['var']) ) {
Code: Select all
if (!empty($_POST['var'])) {really?
is the same as
As in.. the first example won't emit a notice error?
Or is the second example redundant?
Code: Select all
if(!empty($_POST['var']))Code: Select all
if(isset($_POST['var']) && !empty($_POST['var']))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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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:
but if a change for this:
but i dont know if is total correct...
but in that case i would use:
Code: Select all
if ( (isset($_POST['var']) ) && (!empty($_POST['var'])) {
code
}Code: Select all
// will do the same and much better to write
if( @$_POST['']) {
code
}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
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.