views:

74

answers:

3
$_SESSION['user']->getURL()

Is it to call the method of getURL() of object $_SESSION['user']?

A: 

You can't really store objects in a session

I stand corrected:

You can store objects in the session... as long as the class is loaded (or can be autolated) by the time session_start() is called.

or you need to serialize and unserialize them in order to use them in a session.

You might also need a __wakeup function if the class requires a database connection.

http://php.net/manual/en/function.serialize.php

http://php.net/manual/en/function.unserialize.php

[edit]

You probably shouldn't be storing the user object in the session, possibly just an identifier so you can reinstantiate the user object when the page loads (that way the password is not stored in the $_SESSION if it is in the user object)

SeanJA
"You can't really store objects in a session" this is wrong due to session mechanism already did this routine in background.
zerkms
You *can* store objects in the session... as long as the class is loaded (or can be autolated) by the time session_start() is called.
Charles
Yes, you _can_ I guess, but in this case (and probably most cases) he *really* shouldn't be doing that.
SeanJA
If you serialize and unserialize them you don't need to worry about loading the class first.
SeanJA
@Charles: this is good elaboration and i bet it's the trouble questioner got at his question.
zerkms
@SeanJA: "don't worry" isn't mean "you can't".
zerkms
Fixed it (15 chars)
SeanJA
+1 for not storing objects in the session.Yes, it is possible. Is it recommended? Rarely.By just looking at the snippet the user posted, I'd say this is definitely not the case where you'd be better off storing objects in the session.
Isaac
A: 

Is it to call the method of getURL() of object $_SESSION['user']?

Yes, that is how you would do it.

Matt Huggins
A: 

It retrieves the object stored in $_SESSION['user'] and calls its getURL method with no arguments.

Ignacio Vazquez-Abrams