Re: Sessions and Objects
| From: | Szii | Date: | Sat, 17 Jun 2000 21:44:14 +0000 |
| Subject: | Re: Sessions and Objects | ||
| References: | 1 | Groups: | php.dev php.general |
| Request: | Send a blank email to php-dev+get-21643@lists.php.net to get a copy of this message | ||
Couple of us have been asking them to fix this crap for a while, but they're
not even responding.
Best thing we've come up with thus far is to say "if (session_is_registered)"
and then write a copy methind.
myClass1 = new classMine;
if (session_is_registered("session_Mine"
{
myClass1->Load($session_Mine);
}
This doesn't fix your std_class problem, and in trying to replicate it, if
I put
the declarations BEFORE session_start() then I get problems trying to
import my objects (says they're std_class). You COULD just put the class
declarations into a single file, much like an stdafx.h file for windows
programmers
and then include THAT in every program.
It does suck that PHP's so "dumb" about classes in a session. Major flaw,
IMHO,
and really limits the whole idea of classes and pseudo-state session
session objects.
-Szii
At 04:56 PM 6/16/00 -0700, James Du Russel wrote:
>When PHP 4 restores objects from a session, if the class is not defined,
>the object type reverts to 'stdClass' As long as session_start()
>happens belows class definitions, the code works fine.
>
>Here's the problem. Page A creates an object of some type, and stores
>it into the session. The user works with page A for a while, then moves
>over to page B. Page B has no requirement for the object created by
>page A, but the session data is required (for the logged in user object)
>
>When page B loads the session data, it finds an object it does not
>recognize, and thus sets its type to stdClass. When page B is finished,
>it stores the object back into the session, as stdClass! If the user
>goes back to page A, the methods on the object are gone, and lo the page
>is broken!
>
>As an alternative to loading the code for an entire site, I'm
>considering all manner of really ugly serialize/ereg/unserialize tricks
>to work around this. Does anyone have an suggestions for a workaround.
>
>
>
>For the phpdev people, can someone fix this? Better behavior would be
>to preserve the class name, but probably means a lot of internal hacks.
>
>Alternatly, can someone write (I've asked for this before) a simple
>function to force an object into a certain type? It would also be nice
>for it to return the current/old type of an object as well. I envision
>it something like this...
>
>string object_type(object ob, [string newtype])
>
>James
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>