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 :-)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php