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