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