Why is there @ in front...
Moderator: General Moderators
there's one valid instance (at least I think it's valid) where I use the @
I have a header.php file that I include on every page. This page includes a call to session_start();
but sometimes I need to check if a user is logged in (making a call to session_start()) before I load the header page, so I can redirect them to a login page.
Thus, I put the @ in front of session_start to avoid session already started notices.
I have a header.php file that I include on every page. This page includes a call to session_start();
but sometimes I need to check if a user is logged in (making a call to session_start()) before I load the header page, so I can redirect them to a login page.
Thus, I put the @ in front of session_start to avoid session already started notices.
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:
That just smells like bad design.. and not a good reason for @scrotaye wrote:there's one valid instance (at least I think it's valid) where I use the @
I have a header.php file that I include on every page. This page includes a call to session_start();
but sometimes I need to check if a user is logged in (making a call to session_start()) before I load the header page, so I can redirect them to a login page.
Thus, I put the @ in front of session_start to avoid session already started notices.
Ok tell me how this is bad design,
It works great.
It saves time vs writing another if statement
It saves overhead vs calling another php function (isset)
It adheres the programmers practice of writing code to make jobs easier
It's not a security vulnerability
etc. etc..
Code: Select all
if (@$_POST['value'] == 'something') {
// do this
}It saves time vs writing another if statement
It saves overhead vs calling another php function (isset)
It adheres the programmers practice of writing code to make jobs easier
It's not a security vulnerability
etc. etc..
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
How lazy can you get?
That only took about 1-2 seconds..
Code: Select all
if (!empty($_POST['somevar']) && $_POST['somevar'] == 'somevalue') {- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I have something like this written into many projects
Code: Select all
function check($element, $array = '') {
if(func_num_args() < 2 or !is_array($array)) {
$array =& $_REQUEST;
}
$return = (!empty($array) and isset($array[$element]));
return $return;
}
function fetch($element, $default = '', $array = '') {
if(func_num_args() < 3 or !is_array($array)) {
$array =& $_REQUEST;
}
if(check($element, $array)) {
$return = $array[$element];
} else {
$return = $default;
}
return $return;
}- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Even if you organize it like that, isn't the second part of the IF statement still evaluated? Does PHP stop parsing the IF statement at the first failure? If it doesn't then it's pointless to code it like that, and in order to truly accomplish this you would need a nested IF statement.Jcart wrote:How lazy can you get?
That only took about 1-2 seconds..Code: Select all
if (!empty($_POST['somevar']) && $_POST['somevar'] == 'somevalue') {