2012-03-19 59 views
0

假設GeneralNews()返回thisCreateInstance()返回this,前2個方法工作,但最後一個失敗。爲什麼不是新的運算符創建鏈結構?

我不明白爲什麼?

$objGeneralNews = new GeneralNews(); 

$arrDataList = $objGeneralNews->SetWhere('news01date="2011-01-01"')->GetFrontList(); 
var_dump($arrDataList); //This method works 

$arrDataList = GeneralNews::CreateInstance()->SetWhere('news01date="2011-01-01"')->GetFrontList(); 
var_dump($arrDataList); //This method works 

$arrDataList = (new GeneralNews())->SetWhere('news01date="2011-01-01"')->GetFrontList(); 
var_dump($arrDataList); //This method doesn't works 

類代碼GeneralNews:

class GeneralNews {   
    public function GeneralNews(){ 
     return this; 
    } 

    public static function CreateInstance(){ 
     $strClassName = 'GeneralNews'; 
     return new $strClassName; 
    } 
} 
+0

你可以發佈CreateInstance()的代碼和GeneralNews的構造函數嗎? – 2012-03-19 06:56:15

回答