Page 1 of 1

oop shopping cart/cms

Posted: Sat Apr 24, 2010 7:07 am
by greetification
Hi I'm a php OOP beginner, but have worked with OOP languages before. I'm trying to build a CMS/Shopping cart and was wondering if the way I am going about it is correct.

Basically i'm thinking that i'll store the main class inside a session and just serialize/unserialize it when i need to do something. like:

Code: Select all

if (isset($_SESSION['cart'])) {
$cart = unserialize($_SESSION['cart']);
//do stuff
$_SESSION['cart'] = serialize($cart);
}
That way everything is stored in the cart object and it's children and I only have the one session var.

Any thoughts would be appreciated!

Re: oop shopping cart/cms

Posted: Sat Apr 24, 2010 11:58 am
by Christopher
Yes, that is a good way to do it. Remember that you either need to include the class file before starting the session or use autoload(). There are also some new magic functions that can help initialization after unserialize.

Re: oop shopping cart/cms

Posted: Sat Apr 24, 2010 12:38 pm
by greetification
Thanks Christopher,

Are there any security risks (beyond the norm of sessions) to serializing the entire object and it's child objects?

Also, are there any drawbacks in terms of speed?

Thanks!