php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21059 Serialization of objects with references is redundant
Submitted: 2002-12-16 20:23 UTC Modified: 2002-12-22 16:29 UTC
From: milan at acmilan dot hu Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.2.3 OS: Windows XP, Linux
Private report: No CVE-ID: None
 [2002-12-16 20:23 UTC] milan at acmilan dot hu
<?PHP

class A
{
	var $Text;
	var $Parent;
	
	function A(&$parent, $s)
	{
		$this->Text = $s;
		$this->Parent = &$parent;
	}
}

class B
{
	var $Child;
	
	function B()
	{
		$this->Child =& new A($this, "Hello");
	}
}

class C
{
	var $Child;
	
	function C()
	{
		$this->Child = new A($this, "Hello");
	}
}


echo "<pre>\n\n";

$b= new B();
$s = serialize($b);
echo "$s\n" . strlen($s) . "\n";

$s = serialize(&$b);
echo "$s\n" . strlen($s) . "\n";

$b=& new B();
$s = serialize($b);
echo "$s\n" . strlen($s) . "\n";

$s = serialize(&$b);
echo "$s\n" . strlen($s) . "\n";

$c= new C();
$s = serialize($c);
echo "$s\n" . strlen($s) . "\n";

$c=& new C();
$s = serialize(&$c);
echo "$s\n" . strlen($s) . "\n";


echo "</pre>";

?>

-------cut-----------

hello! i tried this script both on windows and linux with PHP 4.2.3 installed. I saw, that the serialized code could be highly redundant, depending on serializing the object or it's refference. there's also a problem around the new constructor, or i guess, the problem might be at copying objects with the '=' operator...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-17 12:00 UTC] milan at acmilan dot hu
here's the output of the script:
http://maldini.dyndns.org/~milan/bug.php
 [2002-12-22 16:29 UTC] milan at acmilan dot hu
hello! i found out that THIS IS NOT A BUG. this is how objects work. when using the = operator, the object is copied and the references inside the object still point to the old object.

SORRY!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC