title: php class variables
body: <p>I have a class named MyCart. </p>
  
  <pre><code>Class MyCartClass
  {
  var $MyCart;  
  
  function getCart(){
    return $this-&gt;MyCart;
  }
  
  function addItem($item){
  
      if ($this-&gt;MyCart){
          $this-&gt;MyCart .= ','.$item;
      } 
      else{
          $this-&gt;MyCart = $item;
      }
  
  }
  
  };
  
  $globalCart = new MyCartClass; // create an instance of the class
  </code></pre>
  
  <p>The variable <code>"$MyCart"</code> is a string containing all the items in the cart, separated with a comma. </p>
  
  <p>Now, I save this class to a file named <code>"cart.php"</code> and I include it in another file.</p>
  
  <p>HOWEVER, every time I call the function <code>"addItem"</code>, the if statement goes to the else branch, which means that the <code>"$MyCart"</code> variable does not contain the current state of the cart.</p>
  
  <p>Do i need to store the state of my cart into a "session" variable? 
  Cause this way it will be accessible from all files for sure..</p>
  
  <p>I would appreciate any kind of help! </p>
  
  <p>Thanks.</p>