1--TEST-- 2Bug #31402 (unserialize() generates references when it should not) 3--INI-- 4error_reporting=E_ALL 5--FILE-- 6<?php 7 8class TestX { 9 var $i; 10 11 function __construct($i) { 12 $this->i = $i; 13 } 14} 15 16class TestY { 17 var $A = array(); 18 var $B; 19 20 function __construct() { 21 $this->A[1] = new TestX(1); 22 $obj = new TestX(2); 23 $this->A[2] = & $obj; 24 $this->A[3] = & $this->A[2]; 25 $this->B = $this->A[1]; 26 } 27} 28 29$before = new TestY(); 30$ser = serialize($before); 31$after = unserialize($ser); 32 33var_dump($before, $after); 34 35?> 36--EXPECTF-- 37object(TestY)#%d (2) { 38 ["A"]=> 39 array(3) { 40 [1]=> 41 object(TestX)#%d (1) { 42 ["i"]=> 43 int(1) 44 } 45 [2]=> 46 &object(TestX)#%d (1) { 47 ["i"]=> 48 int(2) 49 } 50 [3]=> 51 &object(TestX)#%d (1) { 52 ["i"]=> 53 int(2) 54 } 55 } 56 ["B"]=> 57 object(TestX)#%d (1) { 58 ["i"]=> 59 int(1) 60 } 61} 62object(TestY)#%d (2) { 63 ["A"]=> 64 array(3) { 65 [1]=> 66 object(TestX)#%d (1) { 67 ["i"]=> 68 int(1) 69 } 70 [2]=> 71 &object(TestX)#%d (1) { 72 ["i"]=> 73 int(2) 74 } 75 [3]=> 76 &object(TestX)#%d (1) { 77 ["i"]=> 78 int(2) 79 } 80 } 81 ["B"]=> 82 object(TestX)#%d (1) { 83 ["i"]=> 84 int(1) 85 } 86} 87