I assumed that this line indicated a Smarty object:
$gDirSmarty->assign('test', $test);
???
If not, we (or at least I) need some clue as to what it is. (If it is supposed to be using Smarty, then presumably you have to instantiate that object before using it.)
Or if that's a red herring, then I need to know what exactly you want to do.