NYCPHP Meetup

NYPHP.org

[nycphp-talk] More questions about working with forms

John Campbell jcampbell1 at gmail.com
Thu Dec 13 19:01:14 EST 2007


> Can you elaborate on this? I use sessions very often and find them to be very
> useful. After all, they are there to be used, so why not use them when appli
cable?

They do have applications, but most people find way too many applications.

1) Sessions often break a lot of things, typically bookmarks, the back
button, using mutiple windows, and they expire.  These are especially
problems for beginners.
2) Sessions are not a good substitute for a performance cache, and
people tend to use them that way.
3) Sessions make for very hard to find bugs.

Think about how ridiculous it is to save an object to a session.
Let's assume the object has 20 methods and 4 data points.  Serializing
an object and saving one copy for each user is a terrible programming
habit to get into.  What does it even mean to serialize an object?  I
find the concept nonsensical.  Structs (arrays) can be serialized,
objects should not be.  What happens when you unserialize a database
resource? or a Singleton?  or anthing that references something else?

The right solution is to boil down the required information to as
little as possible, and then include it with the request.  And then
you can just do something like $myobj->restore($v1,$v2,$v3,$v4)
If you want a short cut, then save the 4 data points in a session, but
know your form won't work in mutiple windows at the same time.

Regards,
John Campbell



More information about the talk mailing list