Re: objects in sessions again

From: Date: Thu, 22 Apr 2004 17:44:01 +0000
Subject: Re: objects in sessions again
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184262@lists.php.net to get a copy of this message
daniel@electroteque.org wrote:
Hi there, needing some more advise, is this function correct ? function create_object($class_name,$dir = null, $serialize = null) { $dir ? $dir = $dir."/" : $dir = ""; require_once("".CLASS_PATH.$dir.$class_name.".php"); if ($serialize) {
			    if (!isset($_SESSION[''.$class_name.''])) {
$class = new $class_name;
			        $_SESSION[''.$class_name.''] = serialize
($class);
			    }
return unserialize($_SESSION [''.$class_name.'']); } else { return new $class_name; } } i needed to serialize and unserialize or else all hell broke loose. Let me know Thanks. Dan
You really shouldn't have to manually seralize and unserialize the values. The session will do that automatically. Serializing yourself just means that the object is going to be serialized twice. $_SESSION['class'] = new Class(); return $_SESSION['class']; -- paperCrane <Justin Patrin>

« previous php.general (#184262) next »