Is there a better way to check POSTed variables in PHP?

initialization, php

Solution

How about wrapping it in a function?

<?php

function getPost($name, $default = null) {
    return isset($_POST[$name]) ? $_POST[$name] : $default;
}

Problem

I find in my PHP pages I end up with lines and lines of code that look like this: ``` $my_id = isset($_REQUEST['my_id']) ? $_REQUEST['my_id'] : ''; $another_var = isset($_REQUEST['another_var']) ? $_REQUEST['another_var'] : 42; ... ``` Is there a better, more concise, or more readable way to check this array and assign them to a local variable if they exist or apply a default if they don't? EDIT: I don't want to use `register_globals()` - I'd still have the isset problem anyway.

Original source