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