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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC