對不起,對面向對象還是一個新東西。在構造函數中設置默認函數參數
我正在使用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'];
這樣做的最優雅方式是什麼?