NYCPHP Meetup

NYPHP.org

[nycphp-talk] More questions about working with forms

Brian D. brian at realm3.com
Fri Dec 14 08:51:40 EST 2007


I'm going to agree with John on this, with a caveat. $_SESSION in and
of itself is fine, I think the objection boils down to using it for
"application instruction" that should normally be handled by
parameters. Using $_SESSION to pass params from one page to the next
*will* cause problems with users who are browsing your site with more
than one tab. Serializing also is a performance hit, so it should be
used, in my opinion, rather sparingly. It has issues with private &
protected variables, and other oddities.

I could be wrong on this one, but it seems like a mistake to be
throwing objects into a $_SESSION array for the sake of convenience.
Passing $_SESSION user information in the form of an array, or user
preferences, or other structs, would be fine. From that information
and your url params, you'll know what needs to be done.


On Dec 13, 2007 7:01 PM, John Campbell <jcampbell1 at gmail.com> wrote:
> > 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
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>



-- 
realm3 web applications [realm3.com]
freelance consulting, application development
(423) 506-0349



More information about the talk mailing list