Re: PHP 5.0. Save classes in a session. Need help now

From: Date: Thu, 12 May 2005 13:37:44 +0000
Subject: Re: PHP 5.0. Save classes in a session. Need help now
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-215040@lists.php.net to get a copy of this message
Richard Lynch wrote:
On Wed, May 11, 2005 5:19 pm, Oscar Andersson said:
Is it possibele to save a class in a session ex. $cl = new Class(); $SESSION['this_class'] = cl;
hello, Oscar - why don't you try it? notice how 'Class' is a keyword so you can't name a class 'Class' notice how if you use '$SESSION' it won't work even if you start the session correctly... $_SESSION on the other hand will work better :-)
Yes, but... You'd have to actually use $cl in that last line, and you need to require
			     ^ --- notice the dollar sign?
the file that defines the class definition *BEFORE* you start your session in the next page where you expect the class instance to exist.
this is true.
Actually, you could maybe get away with starting the session, the loading the class definition, then accessing the $cl variable... But I'm not sure of that, because I don't use classes, and even if I did, I'd load in all
that wouldn't work - at least none of the methods would be available for use - in affect you have an incomplete object from which you can retrieve all the properties but not call any methods.
the class files before I started my session, just on principle.
personally I have a Session handler class with which I can register classes to be automatically _if_ the session is started.... ;-\ ..mostly because I use lots of classes - and loading them all, everytime is not a good idea - unless you like consistently slow pages :-)


« previous php.general (#215040) next »