English (United Kingdom)Deutsch (DE-CH-AT)
Home Programming PHP Store an object in a PHP session
Store an object in a PHP session PDF Print E-mail
Wednesday, 21 February 2007 00:53

The title is a bit different from what the content describes, but that's intended...

 

You would not want to store an object in a session - you would rather store a reference to an object. This way the object in question is not copied, thus using double memory, for the sake of efficiency.

save the reference:

 
 $_SESSION[”ObjectRef”] = & $RealObject
 

retrieve it:

 
$RealObject = & $_SESSION[”ObjectRef”]
 

Keep in mind that storing objects in session can cause trouble if cookies are used, as a cookie’s size is limited.

 

 

Search

Login