note 27241 deleted from language.types.object by didou

From: Date: Wed, 21 Jul 2004 17:14:09 +0000
Subject: note 27241 deleted from language.types.object by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73834@lists.php.net to get a copy of this message
Note Submitter: adolfoabegg@_plzdontspam_hotmail.com ---- [Editor's note: PHP already does this for you when registering an object in a session, see the third paragraph from the bottom in the page "Serializing objects - objects in sessions"] If you want to use an object with php sessions, you can convert it into a string and then save this string into a session var Try this: ----- obj.php class ShoppingCart{ var $result; function SayHi(){ $result = "Hi there!"; return $result; } } ----- save_obj.php ----- session_start(); session_register('ses_obj'); require ('obj.php'); $Cart = new ShoppingCart; $ses_obj = serialize ($Cart); --------- get_obj.php ---- session_start(); $Cart = unserialize ($HTTP_SESSION_VAR['ses_obj']); $aux = $Cart->SayHi(); print $aux; //prints Hi there!

« previous php.notes (#73834) next »