When I create a function that has optional parameters, I have to think about which one is more likely to be passed the most and that determines the order in which I specify them in the function declaration.
Take the below function with the not so well placed $mandatoryParam:
public function myFunc($mightBeEmptyA, $mightBeEmptyB, $mandatoryParam)
{
}
Is it better practice and would it be better to do the following?:
...
$this->myFunc(array('mightBeEmptyA' => 'myValue')) ;
...
public function myFunc($params)
{
if($params['mightBeEmptyA'])
{
// Do something....
}
}
Using an array to pass in parameters instead. Is the extra logic needed to process the parameters in the array worthwhile?