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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: milan at acmilan dot hu
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2021 The PHP Group
All rights reserved.
Last updated: Tue Oct 19 15:03:35 2021 UTC