I have a class called 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;
A variable "$MyCart"is a string containing all the items in the basket, separated by a comma.
Now I save this class in a file with the name "cart.php"and include it in another file.
HOWEVER, every time I call a function "addItem", the if statement goes to the else branch, which means that the variable "$MyCart"does not contain the current state of the basket.
Do I need to store the state of my basket in the "session" variable? Because it will be available from all files for sure ..
I would be grateful for any help!
Thank.
source
share