As mentioned above, you will not be able to skip parameters. I've written this answer to provide some addendum, which was too large to place in a comment.
@Frank Nocke proposes to call the function with its default parameters, so for example having
function a($b=0, $c=NULL, $d=''){ //...
you should use
$var = a(0, NULL, 'ddd');
which will functionally be the same as omitting the first two ($b
and $c
) parameters.
It is not clear which ones are defaults (is 0
typed to provide default value, or is it important?).
There is also a danger that default values problem is connected to external (or built-in) function, when the default values could be changed by function (or method) author. So if you wouldn't change your call in the program, you could unintentionally change its behaviour.
Some workaround could be to define some global constants, like DEFAULT_A_B
which would be "default value of B parameter of function A" and "omit" parameters this way:
$var = a(DEFAULT_A_B, DEFAULT_A_C, 'ddd');
For classes it is easier and more elegant if you define class constants, because they are part of global scope, eg.
class MyObjectClass {
const DEFAULT_A_B = 0;
function a($b = self::DEFAULT_A_B){
// method body
}
}
$obj = new MyObjectClass();
$var = $obj->a(MyObjectClass::DEFAULT_A_B); //etc.
Note that this default constant is defined exactly once throughout the code (there is no value even in method declaration), so in case of some unexpected changes, you will always supply the function/method with correct default value.
The clarity of this solution is of course better than supplying raw default values (like NULL
, 0
etc.) which say nothing to a reader.
(I agree that calling like $var = a(,,'ddd');
would be the best option)
ReflectionFunction
. I posted that answer in a similar question. – Praxis