对不起,对面向对象还是一个新东西。在构造函数中设置默认函数参数
我正在使用CodeIgniter,但这个问题基本上只是PHP OO。
我有为数众多的做类似的事情函数的类文件:
function blah_method($the_id=null)
{
// if no the_id set, set it to user's default
if(!isset($the_id)){
$the_id = $this->member['the_id'];
}
现在,而不是这样做,在每次方法在这个类中,我可以在构造函数中设置呢?所以我仍然可以明确地传递$ the_id,以覆盖它,否则它总是默认为$this->member['the_id'];
这样做的最优雅方式是什么?