i believe you're meant to serialise objects and then register the serialised
version?? Don't quote me on that, never used sessions, but I didn't
read/hear it somewhere

Martin


-----Original Message-----
From: PHP-List [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 05, 2002 4:30 PM
To: [EMAIL PROTECTED]
Subject: [PHP] PHP Classes and Sessions


What is the proper way to transfer class properties through-out my pages...

let's say i have a ShoppingCart Class and i have methods like
addToCart(id, qty) and deleteFromCart(id)
also i have properties like CartItems("id" => array(), "qty"=> array())

this is what i do...

//when the user enters my site, i do some...
-------------
if (!session_is_registered("myCart")){
    $myCart = new ShoppingCart();
    .... (some other stuffs...)
    session_register("myCart");
}
else {
    $myCart = new ShoppingCart();
}

--------------
if the object in the session is not present
i would create an instance and then register 
it to the session.
else if it is present, i would just reconstruct it...
because if i don't, even though it is in the 
sessions, the properties and methods are 
not constructed (no handler, i don't know how 
to call it).

my code works, but is there any other way
to do this, because i think it's kinda slow.... 

another question, is it ok to have a database-driven
shopping cart? i make use of the database to as the 
actual cart holder?


i need your opinions on these....


thanks!



Brian Feliciano





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to