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