Chris Jenkinson wrote:
Currently I have a function which accepts a limited number of parameters:
call_function($function_name, &$var_1, &$var_2);
I wish to modify the function to accept an indefinite number of
parameters, which may or may not be references.
The function call_function() then calls the function specified in
$function_name, with the variables passed as parameters to that function.
Is this possible? Thanks for any help which can be offered.
Something like this (untested) may work, but someone important once said
that if eval is the answer then you're asking the wrong question...
function call_function($function_name, &$vars)
{
$code = '$retval = '.$function.'(';
$params = array();
foreach (array_keys($vars) as $key)
$params[] = '$var['.$key.']';
$code .= implode(',', $params);
$code .= ');';
return eval($code);
}
For more on eval check the manual: http://php.net/eval, but remember
that it is considerably evil and usually involves some extra security
risk to make sure you're checking and double-checking that nothing
coming from the user gets used unsanitized by eval, and preferably not
at all.
Hope that helps.
-Stut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php