Вы хотите что-то вроде следующего?
function test()
{
$num_args = func_num_args();
$args = func_get_args();
switch ($num_args) {
case 0:
return 'none';
break;
case 1:
return $args[0];
break;
case 2:
return $args[0] . ' - ' . $args[1];
break;
default:
return implode($args, ' - ');
break;
}
}
echo test(); // 'none'
echo test(1); // 1
echo test(1, 2); // 1 - 2
echo test(1, 2, 3); // 1 - 2 - 3
Это будет своего рода метод делегирования.
Или как насчет принятия массива, а не параметров?
function funcA($params)
{
extract($params);
echo $a;
}
function funcB($params)
{
extract($params);
echo $a, $b;
}
function funcC($params)
{
extract($params);
echo $a, $b, $c;
}
$funcs = array('funcA', 'funcB', 'funcC');
$selected = $funcs[0];
$selected(array('a' => 'test', 'b' => 'test2'));
// or something like (beware of security issues)
$selected($_GET);