Member array of class is lossing data in php
<p>I'm using a History class which is defined as follows</p>

<pre><code>class History
{
    private $historyArray=array();
  //private $cacheFileNameArray=array();
  public function __construct()
  {

  } 
  public function writeToHistory($query,$dataArray)
  {
      //print_r($this-&gt;historyArray);
   $cacheFileName=$this-&gt;getCacheFileName();
   $query=$query."|"."1"."|".$cacheFileName;
   array_push($this-&gt;historyArray,$query);
   print_r($this-&gt;historyArray);

  }
  public function checkHistoryExits($query)
  {
    $flag=0;
    $index=0;
    //print_r($this-&gt;historyArray);
    foreach($this-&gt;historyArray as $historyElement)
    {
     $sqlQuery=@current(explode("|",$historyElement));
     //echo $sqlQuery;
      if($sqlQuery==$query)
      {
        $flag=1;
        return $index;
      }
      $index++;
    }
    if($flag==0)
      return "false";
    else
      return $index;
  }

}
</code></pre>

<p>Now the problem i identified that the <code>$historyArray</code> is lossing data when i'm using different functions of the class. EG.first i call the <code>writeToHistory</code> method with proper data.in that case the data is pushed to the array (i can see that by using <code>print_r</code>) but when i'm calling the method 2nd time from the same object the value is pushed to the 0 index of the array i.e the previous data lost.Any idea why it is happening?</p>
