default values for function argument array
Posted: Fri Nov 05, 2010 4:31 pm
I want to pass an array of parameters to the parent constructor where I have default values set for all three arguments. When I leave out argument 2, expecting that the default value 'bar2' is taken, a var_dump of $options only gives bar1 and bar3 but no bar2, not even null:
Any suggestions as how to get a default value for foo2?
Code: Select all
class My_SubClass extends My_Class
{
private static $_options = array(
'foo1' => 'bar1',
'foo3' => 'bar3'
);
public function __construct()
{
parent::__construct(self::$_options);
}
}
class My_Class
{
public function __construct($options = array('foo1' => null , 'foo2' => 'bar2', 'foo3' => null))
{
// method
}
// class declaration continued
}