Any syntax like the one you suggested is not possible : if you want several distinct functions, you have to declare all those functions.
Still, a possibility could be that your fn_a, fn_b and fn_c functions just be simple wrappers arround a more complex one :
public function fn_a(){
return fn_all('a');
}
public function fn_b(){
return fn_all('b');
}
public function fn_c(){
return fn_all('c');
}
public function fn_all($name) {
// a lot of complex stuff here
}
With that, depending on the length on the fn_all
function, of course, you would reduce the amount of code-duplication.
Another idea (not sure how this could be done with methods, so I'll demonstrate with functions) would be to use Closures -- which means PHP >= 5.3
The basic idea being that you'd have a first function, that would return another one -- which would bind the parameter passed to the first one :
First, the function that creates the others :
function creator($name) {
return function () use ($name) {
return $name;
};
}
And, then, let's get three functions, using that creator one :
$fn_a = creator('a');
$fn_b = creator('b');
$fn_c = creator('c');
And now, calling those three functions :
echo $fn_a() . '<br />';
echo $fn_b() . '<br />';
echo $fn_c() . '<br />';
We get the following output :
a
b
c
I've never good at explaining how anonymous functions and closures work -- but searching for "closure" on google should help you understand ; note that you can read tutorial about closures in Javascript : the idea is exactly the same.
(And, as closures are new in PHP -- arrived with PHP 5.3 -- you will not find as many tutorials as for Javascript)