$_GET and isset()

Mikey1980 picture Mikey1980 · Aug 31, 2010 · Viewed 11.7k times · Source

I am getting tried of if isset($_GET['whatever'])... before the rest of my if statement. E_NOTICE errors are way to handy to turn off and for $_POST variables I have a solution in my init script..

$POST = (is_array( $_POST ) && count( $_POST ) > 0);

I find this helps self posting scripts look clean.

if ($POST) {
    // now do something with $_POST...
}

I'm not sure how to dynamically do this if you have no idea what the key is? Can anyone help find a similar solution for $_GET variables?

EDIT:

I simply want if ($_GET['whatever'] == "whatever"); to return false if it's not set and no E_NOTICE errors.

EDIT:

Sorry if I'm unclear I'm looking for a solution for $_GET not $_POST--I only am using $_POST as an example of what I hope to achieve.

Answer

Ionuț G. Stan picture Ionuț G. Stan · Aug 31, 2010

Sometimes I use a global GET function:

function GET($key, $default = null) {
    return isset($_GET[$key]) ? $_GET[$key] : $default;
}