Object disappearing across pages
| From: | Sheila Myers | Date: | Wed, 17 Oct 2001 20:14:23 +0000 |
| Subject: | Object disappearing across pages | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-71387@lists.php.net to get a copy of this message | ||
Still working The Shopping Cart From Hell (tm).
My cart object is very simple:
var $items;
var $cart_id;
function
add($sell_price,$qty,$shipping,$tax,$productid,$short_desc,$note)
{
echo "current ".$this->cart_id;
echo "current".$this->items;
if (isset($this->items[$productid])) //if it is already in the cart,
don't add a new occurrence, just update the total quantity
{
$this->items[$productid]["quantity"] += $qty;
}
else
{
$this->items[$productid]=array(
"price"=>$sell_price,
"quantity"=>$qty,
"shipping"=>$shipping,
"tax"=>$tax,
"desc"=>$short_desc,
"note"=>$note);
}
} //end add
//a lot of other methods
}//end class Cart
The object is defined as a session variable in an include file, which is
required_once in all scripts. The class definition is required_once
also.
There is a main.php which handles all the user interaction, db lookups
etc, and passes the info on to the cart methods. What's happening is
that the cart object seems to be destroyed every time, although it's not
hitting the code that creates a new cart. The property $this->cart_id
stays set all through, but if I try to echo $this->items, I get:
'Undefined property: items' in both the cart.php and the main.php (where
I call $sess_cart->items).
This is driving me insane because I know it should be very very simple.
I've read all the online stuff I can find and this should work without
having to serialize/unserialize (I'm using php 4.06). Can anyone spot
something I'm doing wrong?
Thanks,
Sheila