Forum Moderators: coopster

Message Too Old, No Replies

Objects and Sessions

         

rob7591

5:48 pm on May 4, 2008 (gmt 0)

10+ Year Member



Hi,

I wrote my own shopping cart for my site using a string as a session value and it works OK (I use item_id1,qty;item_id2,qty,etc. and then explode it to figure out what's in the cart).

I want to make a new one now, and I can't decide whether to use an object as the cart to make everything a lot easier and more organized.

The only thing that's holding me back is the speed. Is it slow to do the serialize() unserialize() stuff for sessions? Or is there a faster way to use objects with sessions.

If there's no problems with the speed, is there anything else bad about using an object as a shopping cart?

eelixduppy

2:09 am on May 10, 2008 (gmt 0)



It should be fine using serialize with objects and sessions. If I were you, I would write the shopping cart with classes just because it would be much easier to manage and write.

rob7591

3:34 am on May 11, 2008 (gmt 0)

10+ Year Member



Yeah, that's why I want to do it with the class.

I can't just say $_SESSION['cart'] = $cart_class; though, right?

I have to do the serialize() / unserialize() nonsense?

That's the trouble. I read that it's very slow.

Although I don't think it would be too slow in my situation because I'm sure the class will be relatively small. (Most people don't have more than 4 items in their cart at one time, so the class wouldn't be storing much data)

chorny

3:17 pm on May 11, 2008 (gmt 0)

10+ Year Member



If you don't know if it fast or slow, do a benchmark.