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