1--TEST--
2Object serialization / unserialization: references amongst properties
3--FILE--
4<?php
5function check(&$obj) {
6    var_dump($obj);
7    $ser = serialize($obj);
8    var_dump($ser);
9
10    $uobj = unserialize($ser);
11    var_dump($uobj);
12    $uobj->a = "obj->a.changed";
13    var_dump($uobj);
14    $uobj->b = "obj->b.changed";
15    var_dump($uobj);
16    $uobj->c = "obj->c.changed";
17    var_dump($uobj);
18}
19
20echo "\n\n--- a refs b:\n";
21$obj = new stdClass;
22$obj->b = 1;
23$obj->a = &$obj->b;
24$obj->c = 1;
25check($obj);
26
27echo "\n\n--- a refs c:\n";
28$obj = new stdClass;
29$obj->c = 1;
30$obj->a = &$obj->c;
31$obj->b = 1;
32check($obj);
33
34echo "\n\n--- b refs a:\n";
35$obj = new stdClass;
36$obj->a = 1;
37$obj->b = &$obj->a;
38$obj->c = 1;
39check($obj);
40
41echo "\n\n--- b refs c:\n";
42$obj = new stdClass;
43$obj->a = 1;
44$obj->c = 1;
45$obj->b = &$obj->c;
46check($obj);
47
48echo "\n\n--- c refs a:\n";
49$obj = new stdClass;
50$obj->a = 1;
51$obj->b = 1;
52$obj->c = &$obj->a;
53check($obj);
54
55echo "\n\n--- c refs b:\n";
56$obj = new stdClass;
57$obj->a = 1;
58$obj->b = 1;
59$obj->c = &$obj->b;
60check($obj);
61
62echo "\n\n--- a,b refs c:\n";
63$obj = new stdClass;
64$obj->c = 1;
65$obj->a = &$obj->c;
66$obj->b = &$obj->c;
67check($obj);
68
69echo "\n\n--- a,c refs b:\n";
70$obj = new stdClass;
71$obj->b = 1;
72$obj->a = &$obj->b;
73$obj->c = &$obj->b;
74check($obj);
75
76echo "\n\n--- b,c refs a:\n";
77$obj = new stdClass;
78$obj->a = 1;
79$obj->b = &$obj->a;
80$obj->c = &$obj->a;
81check($obj);
82
83echo "Done";
84?>
85--EXPECTF--
86--- a refs b:
87object(stdClass)#%d (3) {
88  ["b"]=>
89  &int(1)
90  ["a"]=>
91  &int(1)
92  ["c"]=>
93  int(1)
94}
95string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";i:1;}"
96object(stdClass)#%d (3) {
97  ["b"]=>
98  &int(1)
99  ["a"]=>
100  &int(1)
101  ["c"]=>
102  int(1)
103}
104object(stdClass)#%d (3) {
105  ["b"]=>
106  &string(14) "obj->a.changed"
107  ["a"]=>
108  &string(14) "obj->a.changed"
109  ["c"]=>
110  int(1)
111}
112object(stdClass)#%d (3) {
113  ["b"]=>
114  &string(14) "obj->b.changed"
115  ["a"]=>
116  &string(14) "obj->b.changed"
117  ["c"]=>
118  int(1)
119}
120object(stdClass)#%d (3) {
121  ["b"]=>
122  &string(14) "obj->b.changed"
123  ["a"]=>
124  &string(14) "obj->b.changed"
125  ["c"]=>
126  string(14) "obj->c.changed"
127}
128
129
130--- a refs c:
131object(stdClass)#%d (3) {
132  ["c"]=>
133  &int(1)
134  ["a"]=>
135  &int(1)
136  ["b"]=>
137  int(1)
138}
139string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";i:1;}"
140object(stdClass)#%d (3) {
141  ["c"]=>
142  &int(1)
143  ["a"]=>
144  &int(1)
145  ["b"]=>
146  int(1)
147}
148object(stdClass)#%d (3) {
149  ["c"]=>
150  &string(14) "obj->a.changed"
151  ["a"]=>
152  &string(14) "obj->a.changed"
153  ["b"]=>
154  int(1)
155}
156object(stdClass)#%d (3) {
157  ["c"]=>
158  &string(14) "obj->a.changed"
159  ["a"]=>
160  &string(14) "obj->a.changed"
161  ["b"]=>
162  string(14) "obj->b.changed"
163}
164object(stdClass)#%d (3) {
165  ["c"]=>
166  &string(14) "obj->c.changed"
167  ["a"]=>
168  &string(14) "obj->c.changed"
169  ["b"]=>
170  string(14) "obj->b.changed"
171}
172
173
174--- b refs a:
175object(stdClass)#%d (3) {
176  ["a"]=>
177  &int(1)
178  ["b"]=>
179  &int(1)
180  ["c"]=>
181  int(1)
182}
183string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";i:1;}"
184object(stdClass)#%d (3) {
185  ["a"]=>
186  &int(1)
187  ["b"]=>
188  &int(1)
189  ["c"]=>
190  int(1)
191}
192object(stdClass)#%d (3) {
193  ["a"]=>
194  &string(14) "obj->a.changed"
195  ["b"]=>
196  &string(14) "obj->a.changed"
197  ["c"]=>
198  int(1)
199}
200object(stdClass)#%d (3) {
201  ["a"]=>
202  &string(14) "obj->b.changed"
203  ["b"]=>
204  &string(14) "obj->b.changed"
205  ["c"]=>
206  int(1)
207}
208object(stdClass)#%d (3) {
209  ["a"]=>
210  &string(14) "obj->b.changed"
211  ["b"]=>
212  &string(14) "obj->b.changed"
213  ["c"]=>
214  string(14) "obj->c.changed"
215}
216
217
218--- b refs c:
219object(stdClass)#%d (3) {
220  ["a"]=>
221  int(1)
222  ["c"]=>
223  &int(1)
224  ["b"]=>
225  &int(1)
226}
227string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"c";i:1;s:1:"b";R:3;}"
228object(stdClass)#%d (3) {
229  ["a"]=>
230  int(1)
231  ["c"]=>
232  &int(1)
233  ["b"]=>
234  &int(1)
235}
236object(stdClass)#%d (3) {
237  ["a"]=>
238  string(14) "obj->a.changed"
239  ["c"]=>
240  &int(1)
241  ["b"]=>
242  &int(1)
243}
244object(stdClass)#%d (3) {
245  ["a"]=>
246  string(14) "obj->a.changed"
247  ["c"]=>
248  &string(14) "obj->b.changed"
249  ["b"]=>
250  &string(14) "obj->b.changed"
251}
252object(stdClass)#%d (3) {
253  ["a"]=>
254  string(14) "obj->a.changed"
255  ["c"]=>
256  &string(14) "obj->c.changed"
257  ["b"]=>
258  &string(14) "obj->c.changed"
259}
260
261
262--- c refs a:
263object(stdClass)#%d (3) {
264  ["a"]=>
265  &int(1)
266  ["b"]=>
267  int(1)
268  ["c"]=>
269  &int(1)
270}
271string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:2;}"
272object(stdClass)#%d (3) {
273  ["a"]=>
274  &int(1)
275  ["b"]=>
276  int(1)
277  ["c"]=>
278  &int(1)
279}
280object(stdClass)#%d (3) {
281  ["a"]=>
282  &string(14) "obj->a.changed"
283  ["b"]=>
284  int(1)
285  ["c"]=>
286  &string(14) "obj->a.changed"
287}
288object(stdClass)#%d (3) {
289  ["a"]=>
290  &string(14) "obj->a.changed"
291  ["b"]=>
292  string(14) "obj->b.changed"
293  ["c"]=>
294  &string(14) "obj->a.changed"
295}
296object(stdClass)#%d (3) {
297  ["a"]=>
298  &string(14) "obj->c.changed"
299  ["b"]=>
300  string(14) "obj->b.changed"
301  ["c"]=>
302  &string(14) "obj->c.changed"
303}
304
305
306--- c refs b:
307object(stdClass)#%d (3) {
308  ["a"]=>
309  int(1)
310  ["b"]=>
311  &int(1)
312  ["c"]=>
313  &int(1)
314}
315string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:3;}"
316object(stdClass)#%d (3) {
317  ["a"]=>
318  int(1)
319  ["b"]=>
320  &int(1)
321  ["c"]=>
322  &int(1)
323}
324object(stdClass)#%d (3) {
325  ["a"]=>
326  string(14) "obj->a.changed"
327  ["b"]=>
328  &int(1)
329  ["c"]=>
330  &int(1)
331}
332object(stdClass)#%d (3) {
333  ["a"]=>
334  string(14) "obj->a.changed"
335  ["b"]=>
336  &string(14) "obj->b.changed"
337  ["c"]=>
338  &string(14) "obj->b.changed"
339}
340object(stdClass)#%d (3) {
341  ["a"]=>
342  string(14) "obj->a.changed"
343  ["b"]=>
344  &string(14) "obj->c.changed"
345  ["c"]=>
346  &string(14) "obj->c.changed"
347}
348
349
350--- a,b refs c:
351object(stdClass)#%d (3) {
352  ["c"]=>
353  &int(1)
354  ["a"]=>
355  &int(1)
356  ["b"]=>
357  &int(1)
358}
359string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";R:2;}"
360object(stdClass)#%d (3) {
361  ["c"]=>
362  &int(1)
363  ["a"]=>
364  &int(1)
365  ["b"]=>
366  &int(1)
367}
368object(stdClass)#%d (3) {
369  ["c"]=>
370  &string(14) "obj->a.changed"
371  ["a"]=>
372  &string(14) "obj->a.changed"
373  ["b"]=>
374  &string(14) "obj->a.changed"
375}
376object(stdClass)#%d (3) {
377  ["c"]=>
378  &string(14) "obj->b.changed"
379  ["a"]=>
380  &string(14) "obj->b.changed"
381  ["b"]=>
382  &string(14) "obj->b.changed"
383}
384object(stdClass)#%d (3) {
385  ["c"]=>
386  &string(14) "obj->c.changed"
387  ["a"]=>
388  &string(14) "obj->c.changed"
389  ["b"]=>
390  &string(14) "obj->c.changed"
391}
392
393
394--- a,c refs b:
395object(stdClass)#%d (3) {
396  ["b"]=>
397  &int(1)
398  ["a"]=>
399  &int(1)
400  ["c"]=>
401  &int(1)
402}
403string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";R:2;}"
404object(stdClass)#%d (3) {
405  ["b"]=>
406  &int(1)
407  ["a"]=>
408  &int(1)
409  ["c"]=>
410  &int(1)
411}
412object(stdClass)#%d (3) {
413  ["b"]=>
414  &string(14) "obj->a.changed"
415  ["a"]=>
416  &string(14) "obj->a.changed"
417  ["c"]=>
418  &string(14) "obj->a.changed"
419}
420object(stdClass)#%d (3) {
421  ["b"]=>
422  &string(14) "obj->b.changed"
423  ["a"]=>
424  &string(14) "obj->b.changed"
425  ["c"]=>
426  &string(14) "obj->b.changed"
427}
428object(stdClass)#%d (3) {
429  ["b"]=>
430  &string(14) "obj->c.changed"
431  ["a"]=>
432  &string(14) "obj->c.changed"
433  ["c"]=>
434  &string(14) "obj->c.changed"
435}
436
437
438--- b,c refs a:
439object(stdClass)#%d (3) {
440  ["a"]=>
441  &int(1)
442  ["b"]=>
443  &int(1)
444  ["c"]=>
445  &int(1)
446}
447string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";R:2;}"
448object(stdClass)#%d (3) {
449  ["a"]=>
450  &int(1)
451  ["b"]=>
452  &int(1)
453  ["c"]=>
454  &int(1)
455}
456object(stdClass)#%d (3) {
457  ["a"]=>
458  &string(14) "obj->a.changed"
459  ["b"]=>
460  &string(14) "obj->a.changed"
461  ["c"]=>
462  &string(14) "obj->a.changed"
463}
464object(stdClass)#%d (3) {
465  ["a"]=>
466  &string(14) "obj->b.changed"
467  ["b"]=>
468  &string(14) "obj->b.changed"
469  ["c"]=>
470  &string(14) "obj->b.changed"
471}
472object(stdClass)#%d (3) {
473  ["a"]=>
474  &string(14) "obj->c.changed"
475  ["b"]=>
476  &string(14) "obj->c.changed"
477  ["c"]=>
478  &string(14) "obj->c.changed"
479}
480Done
481