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