On objects, sessions, and class definitions

From: Date: Tue, 13 Feb 2001 01:48:09 +0000
Subject: On objects, sessions, and class definitions
Groups: php.dev 
Request: Send a blank email to php-dev+get-46460@lists.php.net to get a copy of this message
Hey guys, My name is Chris and I am the project leader for a fairly large software project written in PHP (it's a groupware suite called Eridu, www.eridu.org) My team and I think PHP is a really cool language, and we couldn't have come this far this fast without it. We do have one particular issue though that rears it's ugly head time and time again which I wanted to ask about and get some feedback on. Whenever we need to pass data around the system, we do so by passing objects stored as session variables. As this is a fairly large project, we have many different classes. The definition for each class is stored in a seperate file. Including the class definitions for every class at the top of every page is not a practical option. As mentioned on the manual pages for session_start, it is necessary to include all the relavent class definitions BEFORE calling session_start because PHP does not store whole object session variables (only the data portion) it is necessary to include all the relavent class files BEFORE calling session_start. This leads to a chicken and egg problem since on any given page we don't know what classes have been stored until we make the session variables available by calling session_start. The only way we have found to get around the problem is to create a cookie containing a serialized array of the names of the classes currently stored in the session variables which we can then use to do the includes of the class definitions before we call session_start. We don't like doing this because it is a nasty hack and a proves to be a pretty big headache. I see a few possible solutions to the problem. The first would be to store complete object session variables, i.e. store the actuall code contained in the object's methods as part of the serialized object. The second would be to simplify the session_start function so that it returned the serialized session data instead of unsearializing it back into the environment which would allow it to be greped first for class names or something before being unserialized. The last would be some additional function like session_class_names() which returns the class names of any serialized object in the current session. Are any of these ideas feasable? Should I just shut up and deal with it the way it is? :) Anyway, any feedback at all will be appreciated. -Chris

« previous php.dev (#46460) next »