有没有办法将整个范围传递给函数

Before going into the details of this question, I'd like to point out that I have never seen this done before, and would be rather curious to see if it can actually be done, and if so, how to go about doing it.

I'm currently sitting on a template loader, and to write it, I have chosen to slightly adapt the HAML file format and extend it with a couple of logic operators - loops, mostly. To do so efficiently, I'd need to pass a list of parameters to the template parser...and I'd prefer to avoid this if possible. While brainstorming for alternatives, the idea came around that maybe, just maybe, it would be possible to reference the scope in which the function was called.

Currently, I'm calling the template parser for a file as follows. Suppose test() is a route.

function test() {
   $q = $UserModel->tether($userID)->fetchPermissions();
   Util::Templating()->parse("file.haml");
}

What I'm trying to avoid is being able to access $q without passing a massively long array as second parameter. My original thought was that there might be a way for parse() to inherit the scope in which it was originally called (here, inside test) rather than having its own. Is there a way to manage this, and if so, how efficient is it?

Includes the superglobals as well:

$a = 'Hello World';
$b = range('A','Z');

$scopeVars = get_defined_vars();

var_dump($scopeVars);
test($scopeVars);


function test($scopeVars) {
    extract($scopeVars);

    echo '$a = '; var_dump($a);
    echo '$b = '; var_dump($b);
}

EDIT

Just as an experiment, to eliminate the superglobals:

$a = 'Hello World';
$b = range('A','Z');

$scopeVars = get_user_defined_vars(get_defined_vars());

test($scopeVars);


function test($scopeVars) {
    extract($scopeVars);

    echo '$a = '; var_dump($a);
    echo '$b = '; var_dump($b);
}

function get_user_defined_vars($vars) {
    return array_diff_key(
        $vars, 
        array_flip(
            array('_SERVER','_GET', '_POST', '_REQUEST', '_FILES', '_COOKIE', '_ENV')
        )
    );
}

But removing the superglobals does seem to make it a bit slower

So i think creating a view object setting it properties and than passing it could work. Or instead of object work with array directly. e.g:

function test() {
    $params = array();
    $params['var_1'] = 'qwe1';
    $params['var_2'] = 'qwe2';
    $params['var_3'] = 'qwe3';
    $params['var_4'] = 'qwe4';
    $params['q'] = $UserModel->tether($userID)->fetchPermissions();
    Util::Templating()->parse("file.haml", $params);
}