English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

eg

class Foo
{
var $x,
var $y
function Foo() {}
}

$la = new Foo();
$la->x = "y";
$la->y = "x";

$_SESSION["myobj"] = $la;


??? if not is there an (efficient) work around?

2006-09-25 06:59:49 · 2 answers · asked by digitaldanuk 2 in Computers & Internet Programming & Design

2 answers

You can store an object in a session variable, but you need to serialize it first:

http://www.php.net/serialize

__________

2006-09-27 06:47:48 · answer #1 · answered by NC 7 · 0 0

Yes, you can store objects in the PHP session, but you'll want to use references to avoid PHP just copying the object (and thus using up more memory) e.g.

$_SESSION["myobj"] =& $la; // Storing object

$la =& $_SESSION["myobj"]; // Retrieving object

(For more on PHP references take a look here: http://www.php.net/references)

In terms of efficiency, I'd think twice before storing large objects in the session. It could become an issue if the session data is being stored in client-side cookies, due to cookie size limits.

Hope that helps! :)

2006-09-25 07:18:32 · answer #2 · answered by allididntwant 1 · 1 0

fedest.com, questions and answers