Re: Passing an indefinite number of parameters by reference
| From: | Tom Rogers | Date: | Mon, 08 May 2006 02:21:35 +0000 |
| Subject: | Re: Passing an indefinite number of parameters by reference | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235698@lists.php.net to get a copy of this message | ||
Hi,
Monday, May 8, 2006, 4:20:11 AM, you wrote:
CJ> Hi,
CJ> Currently I have a function which accepts a limited number of parameters:
CJ> call_function($function_name, &$var_1, &$var_2);
CJ> I wish to modify the function to accept an indefinite number of
CJ> parameters, which may or may not be references.
CJ> The function call_function() then calls the function specified in
CJ> $function_name, with the variables passed as parameters to that function.
CJ> Is this possible? Thanks for any help which can be offered.
CJ> Chris
Here is a cutdown version of a class loader I use, It works for php4 and
php5 and with references. It should be easy to modify.
<?php
function &load_class($class_name,$arg1,$arg2,$arg3){
$num_args = func_num_args();
$arg_list = func_get_args();
$vars = '$return =& new '.$class_name.'(';
if($num_args > 1) {
for ($i = 1; $i < $num_args; $i++) {
$vars .= ($i > 1)? ',':'';
$varname = 'variable'.$i;
$$varname =& $arg_list[$i];
$vars .= "\$$varname";
}
}
$vars .= ');';
eval($vars);
return $return;
}
?>
--
regards,
Tom