You could build an array with the element of the signature of your function, filter them and merge it with a default configuration calling all the functions you need.
I made a simple example with defining 2 parameter with different functions.
class foo{
private $configuration;
private function buildDefaultConfiguration() {
return $configuration = array(
'defaultLength' => $this->getDefaultLength(),
'defaultWidth' => $this->getDefaultWidth(),
);
}
public function __construct($givenLength = null, $givenWidth = null) {
$givenConfiguration = array(
'defaultLength' => $givenLength,
'defaultWidth' => $givenWidth
);
$givenConfiguration = array_filter($givenConfiguration);
$defaultConfiguration = $this->buildDefaultConfiguration();
$this->configuration = array_merge($defaultConfiguration, $givenConfiguration);
}
public function test()
{
echo $this->configuration['defaultLength'] . ' - ' . $this->configuration['defaultWidth'];
}
private function getDefaultLength()
{
return 24;
}
private function getDefaultWidth()
{
return 12;
}
}
$foo1 = new foo(13,14);
$foo2 = new foo();
$foo3 = new foo(null, 66);
$foo4 = new foo(66);
$foo1->test();
//result is 13 - 14
$foo2->test();
//result is 24 - 12
$foo3->test();
//result is 24 - 66
$foo4->test();
//result is 66 - 12
You can check a live working example here, formatting isn't great though
Hope this'll help you