我創建了一個類以下方式陣推不工作
class History
{
private $historyArray;
private $cacheFileNameArray=array();
public function __construct()
{
$this->historyArray=array();
}
public function writeToHistory($query)
{
$cacheFileName=$this->getCacheFileName();
$query=$query.chr(219)."1".chr(219).$cacheFileName;
array_push($this->historyArray,$query);
print_r($this->historyArray);
}
}
現在我已經創造了歷史類的一個對象小時,然後我打電話的功能writeToHistory()兩次有2個不同的參數由我想知道array_push()不工作原因在第二次調用該函數的時候查詢應該寫入數組的第一個索引,但實際上數組的第一個元素被替換。任何想法爲什麼?
[無法重現](http://codepad.viper-7.com/7sEild)。 – 2013-02-13 06:12:35
您發佈的代碼按預期工作,所以問題在於其他地方。 – 2013-02-13 06:27:26