Although, according to the docs here on variable variables, they cannot be used on superglobals inside functions or class methods:
Warning
Please note that variable variables cannot be used with PHP's Superglobal arrays within functions or class methods. The variable $this is also a special variable that cannot be referenced dynamically.
You can simply get around that by declaring them as global variables or referencing them through $GLOBALS variable
Example:
<?php
function myFunc ($varname) {
global $$varname;
var_dump($$varname);
}
myFunc('_SERVER'); // works
myFunc('_POST'); // works
function mySecondFunc ($varname) {
var_dump($GLOBALS[$varname]);
}
mySEcondFunc('_SERVER'); // works
mySecondFunc('_POST'); // works
Note: these do not work for $_ENV!