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