The $_SESSION array is already being serialized before saving it to the session datafile. You'll only have to: $_SESSION['cart'] = $cart; And before session_start(): require_once 'fileWhereClassIsDefined'; . . . session_start(); If the class isn't defined before serialization (session start) an instance of stdclass is created. You should define the "magic" member functions __sleep and __wake if you need to reopen any resource needed for your object (resources, as in opened files, opened mysql connectios, mysql queries, ARE NOT serialized) 2006/4/20, Paul Novitski <paul@xxxxxxxxxxxxxxxxxxx>: > > At 05:14 PM 4/20/2006, Steve wrote: > >I'm creating my own Object Oriented PHP Shopping Cart. > > > >I'm confused about the best way to call the functions of the class > >given the "static" nature of the web. > > > >For example, if I have a function addItem($code), how will this be > >called from the catalog or product description pages where the BUY > buttons are? > > > >On the product description page (say for product ABC213), there will > >be a BUY button, but when the button is clicked, obviously I cannot > >immediately call $cart->addItem('ABC213'). So how is this done? > > > Steve, > > One way to preserve your cart object between page requests is to keep > it serialized in the session. > > When the PHP program wakes up: > > // begin session processing > session_start(); > > // if the cart already exists... > if (isset($_SESSION["cart"]) > { > // read the cart from the session > $oCart = unserialize($_SESSION["cart"]); > }else{ > // or create it > $oCart = new CartObject(); > } > > Before the PHP script ends: > > // save the cart to the session > $_SESSION["cart"] = serialize($oCart); > > In the body of the script, you'll use $_GET and/or $_POST arrays to > feed user input into the cart object, and echo functions to write > each new page in response. > > Does this help clarify, or am I stating only what you already know? > > Paul > _________________________ > > Refs: > http://php.net/session > http://php.net/session_start > > http://php.net/serialize > http://php.net/unserialize > > http://php.net/isset > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >