[thelist] [PHP Newbie] Accessing Object attributes from a _S ESSION variable
Marek Kilimajer
kilimajer at webglobe.sk
Wed Oct 29 18:43:36 CST 2003
You can store your objects in session but you must have the class
declared prior to session_start():
require_once('classes/person.php'); // declaration of class person
session_start();
You'll get rid of the __PHP_Incomplete_Class Object
Default session handler uses serialize to store session variables so
there is no advantage in doing the same in your code.
Jacques Capesius wrote:
>>-----Original Message-----
>>From: thelist-bounces at lists.evolt.org
>>[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Jacques Capesius
>>Sent: Wednesday, October 29, 2003 8:06 AM
>>To: 'Thelist at Lists. Evolt. Org'
>>...
>>Obviously, the second line of code above isn't working. My question
>>is, how to I refer to the attribute values of an object I have stored
>>in a session variable?
>>
>>thanks for any help you can offer.
>>
>>-jacques :)
>
>
> John Corry wrote:
>
>>I didn't think you could practically store an object in a session
>>variable.
>>
>>You have to use the serialize() and unserialize() functions.
>>Http://www.php.net/serialize
>>Http://www.php.net/unserialize
>>
>>John
>
>
> Thanks, John, that did the trick. I also found another method of
> accomplishing that same serialization when dealing with objects in sessions:
>
> register_session("person");
>
> ...at the top of the page, I guess, tells PHP to automatically
> serialize/deserialize the data going into / coming out of the named session
> variable.
>
> Do any of you know if there's any sort of advantage / disadvantage to
> accessing the session variables this way, as opposed to...
>
> $_SESSION["person"] = serialize($person); //when writing
>
> and
>
> $person = unserialize($_SESSION["person"]); //when reading
>
> ..?
>
> I'd be interested in hearing your comments on this. Thanks!
>
> -jacques :)
More information about the thelist
mailing list