In C#, there is a new feature coming with 4.0 called Named Arguments and get along well with Optional Parameters.
private static void writeSomething(int a =
You can fake C++-style optional arguments (i.e. all optional arguments are at the end) by checking for set variables:
function foo($a, $b)
{
$x = isset($a) ? $a : 3;
$y = isset($b) ? $b : 4;
print("X = $x, Y = $y\n");
}
@foo(8);
@foo();
It'll trigger a warning, which I'm suppressing with @
. Not the most elegant solution, but syntactically close to what you wanted.
Edit. That was a silly idea. Use variadic arguments instead:
// faking foo($x = 3, $y = 3)
function foo()
{
$args = func_get_args();
$x = isset($args[0]) ? $args[0] : 3;
$y = isset($args[1]) ? $args[1] : 3;
print("X = $x, Y = $y\n");
}
foo(12,14);
foo(8);
foo();