I have a class named MyCart.
Class MyCartClass
{
var $MyCart;
function getCart(){
return $this->MyCart;
}
function addItem($item){
if ($this->MyCart){
$this->MyCart .= ','.$item;
}
else{
$this->MyCart = $item;
}
}
};
$globalCart = new MyCartClass; // create an instance of the class
The variable "$MyCart" is a string containing all the items in the cart, separated with a comma.
Now, I save this class to a file named "cart.php" and I include it in another file.
HOWEVER, every time I call the function "addItem", the if statement goes to the else branch, which means that the "$MyCart" variable does not contain the current state of the cart.
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..
I would appreciate any kind of help!
Thanks.