|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28325 serialization of objects
Submitted: 2004-05-08 12:12 UTC Modified: 2005-02-05 03:40 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: antonr at game dot permonline dot ru Assigned: moriyoshi (profile)
Status: Closed Package: Class/Object related
PHP Version: 4.3.9, 5.0.1 OS: *
Private report: No CVE-ID: None
 [2004-05-08 12:12 UTC] antonr at game dot permonline dot ru
I have one object with property "myclass1", referenced to second object. And property "myclass2" of second object, referenced to first object.
When I serialize the first object and unserialize the result string, I get three objects: two copies of first object and a copy of second object. 

Reproduce code:
  class MyClass1
    { public $myclass2; 
      public $number;

  class MyClass2
    { public $myclass1;

  $a = new MyClass1;
  $a->number = 1;
  $a->myclass2 = new MyClass2;
  $a->myclass2->myclass1 = $a;

  $b = unserialize(serialize($a));
  $b->number = 2;
  echo $b->number;
  echo "\n"; 
  echo $b->myclass2->myclass1->number;

Expected result:
If serialization was made correctly, then we would get that 
$b and $b->myclass2->myclass1 are references to one instance, and the output of script must be:


Actual result:
The actual output is


this means, that $b and $b->myclass2->myclass1 aren't references to the same instance


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-08 12:15 UTC] antonr at game dot permonline dot ru
but if change the line 

$a->myclass2->myclass1 = $a;


$a->myclass2->myclass1 = &$a;

serialization/unserialization works fine
 [2004-06-30 04:51 UTC]

Preliminary patch can be found here:

 [2004-07-05 10:00 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2004-09-25 00:08 UTC]
Fixed in 4.3.10 & 5.0.1
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 10:01:29 2023 UTC