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