[thelist] [PHP Newbie] Accessing Object attributes from a _S ESSION variable

Jacques Capesius jacques_capesius at cnt.com
Wed Oct 29 15:27:48 CST 2003


> 
> -----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