收录日期:2021/01/28 15:49:02 时间:2010-03-31 04:14:17 标签:php,session,object
$_SESSION['user']->getURL()

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

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

Yes, that is how you would do it.

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)

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