1--TEST--
2Object serialization / unserialization: real references and COW references
3--FILE--
4<?php
5echo "\n\nArray containing same object twice:\n";
6$obj = new stdclass;
7$a[0] = $obj;
8$a[1] = $a[0];
9var_dump($a);
10
11$ser = serialize($a);
12var_dump($ser);
13
14$ua = unserialize($ser);
15var_dump($ua);
16$ua[0]->a = "newProp";
17var_dump($ua);
18$ua[0] = "a0.changed";
19var_dump($ua);
20
21
22echo "\n\nArray containing object and reference to that object:\n";
23$obj = new stdclass;
24$a[0] = $obj;
25$a[1] = &$a[0];
26var_dump($a);
27
28$ser = serialize($a);
29var_dump($ser);
30
31$ua = unserialize($ser);
32var_dump($ua);
33$ua[0]->a = "newProp";
34var_dump($ua);
35$ua[0] = "a0.changed";
36var_dump($ua);
37
38echo "\n\nObject containing same object twice:";
39$obj = new stdclass;
40$contaner = new stdclass;
41$contaner->a = $obj;
42$contaner->b = $contaner->a;
43var_dump($contaner);
44
45$ser = serialize($contaner);
46var_dump($ser);
47
48$ucontainer = unserialize($ser);
49var_dump($ucontainer);
50$ucontainer->a->a = "newProp";
51var_dump($ucontainer);
52$ucontainer->a = "container->a.changed";
53var_dump($ucontainer);
54
55
56echo "\n\nObject containing object and reference to that object:\n";
57$obj = new stdclass;
58$contaner = new stdclass;
59$contaner->a = $obj;
60$contaner->b = &$contaner->a;
61var_dump($contaner);
62
63$ser = serialize($contaner);
64var_dump($ser);
65
66$ucontainer = unserialize($ser);
67var_dump($ucontainer);
68$ucontainer->a->a = "newProp";
69var_dump($ucontainer);
70$ucontainer->b = "container->a.changed";
71var_dump($ucontainer);
72
73echo "Done";
74?>
75--EXPECTF--
76Array containing same object twice:
77array(2) {
78  [0]=>
79  object(stdClass)#%d (0) {
80  }
81  [1]=>
82  object(stdClass)#%d (0) {
83  }
84}
85string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;r:2;}"
86array(2) {
87  [0]=>
88  object(stdClass)#%d (0) {
89  }
90  [1]=>
91  object(stdClass)#%d (0) {
92  }
93}
94array(2) {
95  [0]=>
96  object(stdClass)#%d (1) {
97    ["a"]=>
98    string(7) "newProp"
99  }
100  [1]=>
101  object(stdClass)#%d (1) {
102    ["a"]=>
103    string(7) "newProp"
104  }
105}
106array(2) {
107  [0]=>
108  string(10) "a0.changed"
109  [1]=>
110  object(stdClass)#%d (1) {
111    ["a"]=>
112    string(7) "newProp"
113  }
114}
115
116
117Array containing object and reference to that object:
118array(2) {
119  [0]=>
120  &object(stdClass)#%d (0) {
121  }
122  [1]=>
123  &object(stdClass)#%d (0) {
124  }
125}
126string(37) "a:2:{i:0;O:8:"stdClass":0:{}i:1;R:2;}"
127array(2) {
128  [0]=>
129  &object(stdClass)#%d (0) {
130  }
131  [1]=>
132  &object(stdClass)#%d (0) {
133  }
134}
135array(2) {
136  [0]=>
137  &object(stdClass)#%d (1) {
138    ["a"]=>
139    string(7) "newProp"
140  }
141  [1]=>
142  &object(stdClass)#%d (1) {
143    ["a"]=>
144    string(7) "newProp"
145  }
146}
147array(2) {
148  [0]=>
149  &string(10) "a0.changed"
150  [1]=>
151  &string(10) "a0.changed"
152}
153
154
155Object containing same object twice:object(stdClass)#%d (2) {
156  ["a"]=>
157  object(stdClass)#%d (0) {
158  }
159  ["b"]=>
160  object(stdClass)#%d (0) {
161  }
162}
163string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";r:2;}"
164object(stdClass)#%d (2) {
165  ["a"]=>
166  object(stdClass)#%d (0) {
167  }
168  ["b"]=>
169  object(stdClass)#%d (0) {
170  }
171}
172object(stdClass)#%d (2) {
173  ["a"]=>
174  object(stdClass)#%d (1) {
175    ["a"]=>
176    string(7) "newProp"
177  }
178  ["b"]=>
179  object(stdClass)#%d (1) {
180    ["a"]=>
181    string(7) "newProp"
182  }
183}
184object(stdClass)#%d (2) {
185  ["a"]=>
186  string(20) "container->a.changed"
187  ["b"]=>
188  object(stdClass)#%d (1) {
189    ["a"]=>
190    string(7) "newProp"
191  }
192}
193
194
195Object containing object and reference to that object:
196object(stdClass)#%d (2) {
197  ["a"]=>
198  &object(stdClass)#%d (0) {
199  }
200  ["b"]=>
201  &object(stdClass)#%d (0) {
202  }
203}
204string(58) "O:8:"stdClass":2:{s:1:"a";O:8:"stdClass":0:{}s:1:"b";R:2;}"
205object(stdClass)#%d (2) {
206  ["a"]=>
207  &object(stdClass)#%d (0) {
208  }
209  ["b"]=>
210  &object(stdClass)#%d (0) {
211  }
212}
213object(stdClass)#%d (2) {
214  ["a"]=>
215  &object(stdClass)#%d (1) {
216    ["a"]=>
217    string(7) "newProp"
218  }
219  ["b"]=>
220  &object(stdClass)#%d (1) {
221    ["a"]=>
222    string(7) "newProp"
223  }
224}
225object(stdClass)#%d (2) {
226  ["a"]=>
227  &string(20) "container->a.changed"
228  ["b"]=>
229  &string(20) "container->a.changed"
230}
231Done
232