Code: Select all
$action = (int)$_GET['action'];Moderator: General Moderators
Code: Select all
$action = (int)$_GET['action'];Code: Select all
$action = isset($_GET['action']) ? (int)$_GET['action'] : 0;Code: Select all
if (isset($_GET['action'])) {
$action = (int)$_GET['action'];
}
else {
#...
}Code: Select all
$action = isset($_GET['action']) ? (int)$_GET['action'] : 0;Code: Select all
function _init_var($var, $key, $val)
{
return (!empty($var[$key]) && isset($var[$key]) ? $var[$key] : $val);
}woohoo!volka wrote:There will probably a shorter expression in php6, see http://www.php.net/~derick/meeting-note ... thing-elseCode: Select all
$action = isset($_GET['action']) ? (int)$_GET['action'] : 0;
Ditto!!Jcart wrote:woohoo!volka wrote:There will probably a shorter expression in php6, see http://www.php.net/~derick/meeting-note ... thing-elseCode: Select all
$action = isset($_GET['action']) ? (int)$_GET['action'] : 0;
You mean for my function or the original statement? My function assumes each will be set...and they always will be.feyd wrote:If you do not pass the key, PHP will throw errors when it doesn't exist.
I was replying to Skara's statement that $foo['bar'] would work, instead of sending the key to the function. Your function appears okay.Hockey wrote:You mean for my function or the original statement? My function assumes each will be set...and they always will be.
I just hate using error surpression and needed a simple function do do the trick as superglobal access is common - I use POST and GET inside individual controllers so I don't initialize these in the front controller (bad design or not).
Code: Select all
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;
}
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 makeDefine($name, $value = true) {
if(!defined($name)) {
define($name,$value);
}
}Code: Select all
$action = @(int)$_GET['action'];