Why can't you, outside of global scope, access superglobals directly through variables, as in $v = '_GET'; $array = $$v;
Prefacing the code with global $$v; works. As does using $GLOBALS[$v] instead of $$v;
echo 'Code residees in global scope<br>';
$required = array('_GET' => array('stuff'));
foreach ($required as $location => $indata)
{
$array = $$location;
foreach ($indata as $key)
{
if (!isset($array[$key]));
}
}
function verify_request_data($required)
{
foreach ($required as $location => $indata)
{
/* Can access the superglobal if you first specify
global $$location
Uncomment below to see that it works
*/
# global $$location;
$array = $$location;
/* or replace the above with
*/
# $array = $GLOBALS[$location];
foreach ($indata as $key)
{
if (!isset($array[$key]));
}
}
}
echo '<br><br>Using the same code wrapped in a function<br>';
verify_request_data($required);