oop shopping cart/cms

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
greetification
Forum Newbie
Posts: 4
Joined: Thu Apr 22, 2010 3:19 pm

oop shopping cart/cms

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: oop shopping cart/cms

Post 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.
(#10850)
greetification
Forum Newbie
Posts: 4
Joined: Thu Apr 22, 2010 3:19 pm

Re: oop shopping cart/cms

Post 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!
Post Reply