When writing controllers for Symfony 2, I often need to pass quite a few variables to the template like return array('param1' => $param1, 'anotherBigParam' => $anotherBigParam, 'yetAnotherParam' => $yetAnotherParam);
With many parameters this ends up really long and ugly, so I thought about creating a helper function for it:
public function indexAction()
{
$param1 = 'fee';
$anotherBigParam = 'foe';
$yetAnotherParam = 'fum';
return $this->vars('param1', 'anotherBigParam', 'yetAnotherParam');
}
private function vars() {
$arr = array();
foreach(func_get_args() as $arg) {
$arr[$arg] = $$arg;
}
return $arr;
}
Is there some kind of drawback or risk from doing this? Does PHP or Symfony 2 already provide a better or cleaner way to achieve the same result?