Page 1 of 1

Object Serialization breaks references on PHP 4.3.9

Posted: Thu Jul 21, 2005 6:41 am
by lucianodenti@yahoo.it
I need help for this big problem.
I can't mantain objects references after serialize/unserialize operations

this is a code sample:

Code: Select all

<?php

class myclass {
	
	var $a;
	
	function myclass(){
		$this->a = ""; //empty
	}
}

session_start();

if(!isset($_SESSION['test'])){
	$test = new myclass;
	$test1 = &$test; //this is a reference to '$test'
	$test1->a = "test ok"; //now it's ok, '$test1' point to '$test'
	//serialization
	$_SESSION['test'] = serialize($test);
	$_SESSION['test1'] = serialize($test1);
} else {
	//after a page refresh I can unserialize variables but ...
	$test = unserialize($_SESSION['test']);
	$test1 = unserialize($_SESSION['test1']);
	$test->a = "test";
	$test1->a = "test1"; //now 'a' member variable is contained in a NEW OBJECT of type myclass !!!
}

?>
Any suggestions ?