1--TEST--
2serialization: arrays with references to the containing array
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(&$a) {
17	var_dump($a);
18	$ser = serialize($a);
19	var_dump($ser);
20
21	$b = unserialize($ser);
22	var_dump($b);
23	$b[0] = "b0.changed";
24	var_dump($b);
25	$b[1] = "b1.changed";
26	var_dump($b);
27	$b[2] = "b2.changed";
28	var_dump($b);
29}
30
31echo "\n\n--- 1 refs container:\n";
32$a = array();
33$a[0] = &$a;
34$a[1] = 1;
35$a[2] = 1;
36check($a);
37
38echo "\n\n--- 1,2 ref container:\n";
39$a = array();
40$a[0] = &$a;
41$a[1] = &$a;
42$a[2] = 1;
43check($a);
44
45echo "\n\n--- 1,2,3 ref container:\n";
46$a = array();
47$a[0] = &$a;
48$a[1] = &$a;
49$a[2] = &$a;
50check($a);
51
52echo "Done";
53?>
54--EXPECT--
55--- 1 refs container:
56array(3) {
57  [0]=>
58  &array(3) {
59    [0]=>
60    *RECURSION*
61    [1]=>
62    int(1)
63    [2]=>
64    int(1)
65  }
66  [1]=>
67  int(1)
68  [2]=>
69  int(1)
70}
71string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;i:1;i:2;i:1;}i:1;i:1;i:2;i:1;}"
72array(3) {
73  [0]=>
74  &array(3) {
75    [0]=>
76    *RECURSION*
77    [1]=>
78    int(1)
79    [2]=>
80    int(1)
81  }
82  [1]=>
83  int(1)
84  [2]=>
85  int(1)
86}
87array(3) {
88  [0]=>
89  string(10) "b0.changed"
90  [1]=>
91  int(1)
92  [2]=>
93  int(1)
94}
95array(3) {
96  [0]=>
97  string(10) "b0.changed"
98  [1]=>
99  string(10) "b1.changed"
100  [2]=>
101  int(1)
102}
103array(3) {
104  [0]=>
105  string(10) "b0.changed"
106  [1]=>
107  string(10) "b1.changed"
108  [2]=>
109  string(10) "b2.changed"
110}
111
112
113--- 1,2 ref container:
114array(3) {
115  [0]=>
116  &array(3) {
117    [0]=>
118    *RECURSION*
119    [1]=>
120    *RECURSION*
121    [2]=>
122    int(1)
123  }
124  [1]=>
125  &array(3) {
126    [0]=>
127    *RECURSION*
128    [1]=>
129    *RECURSION*
130    [2]=>
131    int(1)
132  }
133  [2]=>
134  int(1)
135}
136string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;i:1;}i:1;R:2;i:2;i:1;}"
137array(3) {
138  [0]=>
139  &array(3) {
140    [0]=>
141    *RECURSION*
142    [1]=>
143    *RECURSION*
144    [2]=>
145    int(1)
146  }
147  [1]=>
148  &array(3) {
149    [0]=>
150    *RECURSION*
151    [1]=>
152    *RECURSION*
153    [2]=>
154    int(1)
155  }
156  [2]=>
157  int(1)
158}
159array(3) {
160  [0]=>
161  &string(10) "b0.changed"
162  [1]=>
163  &string(10) "b0.changed"
164  [2]=>
165  int(1)
166}
167array(3) {
168  [0]=>
169  &string(10) "b1.changed"
170  [1]=>
171  &string(10) "b1.changed"
172  [2]=>
173  int(1)
174}
175array(3) {
176  [0]=>
177  &string(10) "b1.changed"
178  [1]=>
179  &string(10) "b1.changed"
180  [2]=>
181  string(10) "b2.changed"
182}
183
184
185--- 1,2,3 ref container:
186array(3) {
187  [0]=>
188  &array(3) {
189    [0]=>
190    *RECURSION*
191    [1]=>
192    *RECURSION*
193    [2]=>
194    *RECURSION*
195  }
196  [1]=>
197  &array(3) {
198    [0]=>
199    *RECURSION*
200    [1]=>
201    *RECURSION*
202    [2]=>
203    *RECURSION*
204  }
205  [2]=>
206  &array(3) {
207    [0]=>
208    *RECURSION*
209    [1]=>
210    *RECURSION*
211    [2]=>
212    *RECURSION*
213  }
214}
215string(56) "a:3:{i:0;a:3:{i:0;R:2;i:1;R:2;i:2;R:2;}i:1;R:2;i:2;R:2;}"
216array(3) {
217  [0]=>
218  &array(3) {
219    [0]=>
220    *RECURSION*
221    [1]=>
222    *RECURSION*
223    [2]=>
224    *RECURSION*
225  }
226  [1]=>
227  &array(3) {
228    [0]=>
229    *RECURSION*
230    [1]=>
231    *RECURSION*
232    [2]=>
233    *RECURSION*
234  }
235  [2]=>
236  &array(3) {
237    [0]=>
238    *RECURSION*
239    [1]=>
240    *RECURSION*
241    [2]=>
242    *RECURSION*
243  }
244}
245array(3) {
246  [0]=>
247  &string(10) "b0.changed"
248  [1]=>
249  &string(10) "b0.changed"
250  [2]=>
251  &string(10) "b0.changed"
252}
253array(3) {
254  [0]=>
255  &string(10) "b1.changed"
256  [1]=>
257  &string(10) "b1.changed"
258  [2]=>
259  &string(10) "b1.changed"
260}
261array(3) {
262  [0]=>
263  &string(10) "b2.changed"
264  [1]=>
265  &string(10) "b2.changed"
266  [2]=>
267  &string(10) "b2.changed"
268}
269Done
270