note 27241 added to language.types.object

From: Date: Thu, 28 Nov 2002 18:26:38 +0000
Subject: note 27241 added to language.types.object
Groups: php.notes 
Request: Send a blank email to php-notes+get-40078@lists.php.net to get a copy of this message
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! -- http://www.php.net/manual/en/language.types.object.php http://master.php.net/manage/user-notes.php?action=edit+27241 http://master.php.net/manage/user-notes.php?action=delete+27241 http://master.php.net/manage/user-notes.php?action=reject+27241

« previous php.notes (#40078) next »