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