我試圖獲取類的屬性在PHPPHP - 類財產問題
class Test(){
public function import($data) {
$im = new import($this, $data);
$im->getInfo();
$this->fileInfo = $im->getRecord();
new ImportData($this, $this->fileInfo);
return true;
}
public function getFilePath(){
return $this->fileInfo;
}
}
在我的其他文件。
$import = new Test();
$filePath = $import ->getFilePath();
//$filePath returns nothing becasue $this->fileInfo is not init yet.
//my other codes here.
//my other codes here.
//call import method here.
$import ->import($data);
我需要調用getFilePath
前import
方法,但我只能得到$this->fileInfo
在import
方法。 有沒有反正呢?非常感謝!
'class test(){...}'是不對的。 http://www.php.net/manual/en/language.oop5.basic.php – Ejaz 2013-04-25 20:59:08
對不起,這只是一個快速的錯字。謝謝你的提示。 – Rouge 2013-04-25 21:00:17
是的,你的代碼沒有多大意義。就像,當你創建並填充一個新的ImportData對象時('New ImportData($ this,$ this-> fileInfo)'),但是不要將它分配給任何東西,導致一個對象無法真正引用它。 – 2013-04-25 21:01:04