Re: Object disappearing across pages

From: Date: Wed, 17 Oct 2001 20:33:42 +0000
Subject: Re: Object disappearing across pages
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-71396@lists.php.net to get a copy of this message
make sure you are defining the class THEN starting the session, its very important the class is defined FIRST. I dont knwo if this is the problem or not, but it has pissed me off before. another place to look is in the acual session file, find out there the session files are stored, is the data your expecting in there ? -- Chris Lee lee@mediawaveonline.com "Sheila Myers" <sheila@consys.com> wrote in message news:3BCDE69F.F8379EE9@consys.com... > 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

« previous php.general (#71396) next »