Object Serialization breaks references on PHP 4.3.9

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lucianodenti@yahoo.it

Object Serialization breaks references on PHP 4.3.9

Post 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 ?
Post Reply