Re: variable-length arguments passed by reference... how?

From: Date: Thu, 29 Apr 2004 17:51:19 +0000
Subject: Re: variable-length arguments passed by reference... how?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-184968@lists.php.net to get a copy of this message
A bit like this $num_args = func_num_args(); $arg_list = func_get_args(); $vars = 'function_to_call('; for ($i = 0; $i < $num_args; $i++) { $vars .= ($i > 0)? ',':''; $varname = 'variable'.$i; $$varname =& $arg_list[$i]; $vars .= "\$$varname"; } $vars .= ');'; //that leaves you with a string you can use eval on eval($vars);
I know I'm probably paranoid, but eval() always bugs me. I think for what you want to do you can use call_user_func_array() $args = func_get_args(); call_user_func_array('function_to_call', $args); http://www.php.net/manual/en/function.call-user-func-array.php

« previous php.general (#184968) next »