I am new to php and have coding experience in java and C. So optional parameter is a bit confusing for me. I would like to know that if a function has two optional parameters and if I pass a single argument, which parameter will be mapped against the argument?
Share
The first argument is always passed to the first variable in the parameters, the second to the second and so on, regardless of whether they are optional or not.
The only difference between an optional and a non-optional parameter is that a warning is thrown when there are not enough arguments in the call to fulfill all non-optional parameters.
Inside the function
$awill be “x”,$band$cwill be null and$dwill be 2 but a warning will be thrown.Therefore it makes no sense to have optional parameters left of non-optional ones – although that would be syntactically correct – because you could never leave them out in the call without generation a warning.