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