How can I do this without using eval() ??
Posted: Wed Dec 22, 2010 6:20 pm
Hi, I have one function which can accept an arbitrary number of variables. I want to pass all of these variables to another function. I have written the following script to do this.
Does anyone have a way of doing this without using the eval() construct? This method will get called frequently, and it would be far more efficient to not use eval(). Also, I have heard the quotation "if eval is the answer then you are probably asking the wrong question", so I feel like I should be doing all I can to avoid using it!
Code: Select all
public function addMeta()
{
$args = '';
$numargs = func_num_args();
$params = func_get_args();
$i = 0;
foreach($params as $value)
{
$i++;
$args .= '\''.$value.'\'';
if($i != $numargs)
{
$args .= ', ';
}
}
return eval('$this->addClosedTag($args);');
}