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?