1--TEST--
2Pass uninitialised objects and arrays by reference to test implicit initialisation.
3--FILE--
4<?php
5
6function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) {
7  $ref1 = "Ref1 changed";
8  $ref2 = "Ref2 changed";
9  $ref3 = "Ref3 changed";
10  $ref4 = "Ref4 changed";
11  $ref5 = "Ref5 changed";
12}
13
14
15class C {
16
17	function __construct(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) {
18	  $ref1 = "Ref1 changed";
19	  $ref2 = "Ref2 changed";
20	  $ref3 = "Ref3 changed";
21	  $ref4 = "Ref4 changed";
22	  $ref5 = "Ref5 changed";
23	}
24
25	function refs(&$ref1, &$ref2, &$ref3, &$ref4, &$ref5) {
26	  $ref1 = "Ref1 changed";
27	  $ref2 = "Ref2 changed";
28	  $ref3 = "Ref3 changed";
29	  $ref4 = "Ref4 changed";
30	  $ref5 = "Ref5 changed";
31	}
32
33}
34
35echo "\n ---- Pass uninitialised array & object by ref: function call ---\n";
36unset($u1, $u2, $u3, $u4, $u5);
37refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
38var_dump($u1, $u2, $u3, $u4, $u5);
39
40echo "\n ---- Pass uninitialised arrays & objects by ref: static method call ---\n";
41unset($u1, $u2, $u3, $u4, $u5);
42C::refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
43var_dump($u1, $u2, $u3, $u4, $u5);
44
45echo "\n\n---- Pass uninitialised arrays & objects by ref: constructor ---\n";
46unset($u1, $u2, $u3, $u4, $u5);
47$c = new C($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
48var_dump($u1, $u2, $u3, $u4, $u5);
49
50echo "\n ---- Pass uninitialised arrays & objects by ref: instance method call ---\n";
51unset($u1, $u2, $u3, $u4, $u5);
52$c->refs($u1[0], $u2[0][1], $u3->a, $u4->a->b, $u5->a->b->c);
53var_dump($u1, $u2, $u3, $u4, $u5);
54
55?>
56--EXPECTF--
57 ---- Pass uninitialised array & object by ref: function call ---
58
59Warning: Creating default object from empty value in %spassByReference_006.php on line %d
60
61Warning: Creating default object from empty value in %spassByReference_006.php on line %d
62
63Warning: Creating default object from empty value in %spassByReference_006.php on line %d
64
65Warning: Creating default object from empty value in %spassByReference_006.php on line %d
66
67Warning: Creating default object from empty value in %spassByReference_006.php on line %d
68
69Warning: Creating default object from empty value in %spassByReference_006.php on line %d
70array(1) {
71  [0]=>
72  string(12) "Ref1 changed"
73}
74array(1) {
75  [0]=>
76  array(1) {
77    [1]=>
78    string(12) "Ref2 changed"
79  }
80}
81object(stdClass)#%d (1) {
82  ["a"]=>
83  string(12) "Ref3 changed"
84}
85object(stdClass)#%d (1) {
86  ["a"]=>
87  object(stdClass)#%d (1) {
88    ["b"]=>
89    string(12) "Ref4 changed"
90  }
91}
92object(stdClass)#%d (1) {
93  ["a"]=>
94  object(stdClass)#%d (1) {
95    ["b"]=>
96    object(stdClass)#%d (1) {
97      ["c"]=>
98      string(12) "Ref5 changed"
99    }
100  }
101}
102
103 ---- Pass uninitialised arrays & objects by ref: static method call ---
104
105Deprecated: Non-static method C::refs() should not be called statically in %s on line 39
106
107Warning: Creating default object from empty value in %spassByReference_006.php on line %d
108
109Warning: Creating default object from empty value in %spassByReference_006.php on line %d
110
111Warning: Creating default object from empty value in %spassByReference_006.php on line %d
112
113Warning: Creating default object from empty value in %spassByReference_006.php on line %d
114
115Warning: Creating default object from empty value in %spassByReference_006.php on line %d
116
117Warning: Creating default object from empty value in %spassByReference_006.php on line %d
118array(1) {
119  [0]=>
120  string(12) "Ref1 changed"
121}
122array(1) {
123  [0]=>
124  array(1) {
125    [1]=>
126    string(12) "Ref2 changed"
127  }
128}
129object(stdClass)#%d (1) {
130  ["a"]=>
131  string(12) "Ref3 changed"
132}
133object(stdClass)#%d (1) {
134  ["a"]=>
135  object(stdClass)#%d (1) {
136    ["b"]=>
137    string(12) "Ref4 changed"
138  }
139}
140object(stdClass)#%d (1) {
141  ["a"]=>
142  object(stdClass)#%d (1) {
143    ["b"]=>
144    object(stdClass)#%d (1) {
145      ["c"]=>
146      string(12) "Ref5 changed"
147    }
148  }
149}
150
151
152---- Pass uninitialised arrays & objects by ref: constructor ---
153
154Warning: Creating default object from empty value in %spassByReference_006.php on line %d
155
156Warning: Creating default object from empty value in %spassByReference_006.php on line %d
157
158Warning: Creating default object from empty value in %spassByReference_006.php on line %d
159
160Warning: Creating default object from empty value in %spassByReference_006.php on line %d
161
162Warning: Creating default object from empty value in %spassByReference_006.php on line %d
163
164Warning: Creating default object from empty value in %spassByReference_006.php on line %d
165array(1) {
166  [0]=>
167  string(12) "Ref1 changed"
168}
169array(1) {
170  [0]=>
171  array(1) {
172    [1]=>
173    string(12) "Ref2 changed"
174  }
175}
176object(stdClass)#%d (1) {
177  ["a"]=>
178  string(12) "Ref3 changed"
179}
180object(stdClass)#%d (1) {
181  ["a"]=>
182  object(stdClass)#%d (1) {
183    ["b"]=>
184    string(12) "Ref4 changed"
185  }
186}
187object(stdClass)#%d (1) {
188  ["a"]=>
189  object(stdClass)#%d (1) {
190    ["b"]=>
191    object(stdClass)#%d (1) {
192      ["c"]=>
193      string(12) "Ref5 changed"
194    }
195  }
196}
197
198 ---- Pass uninitialised arrays & objects by ref: instance method call ---
199
200Warning: Creating default object from empty value in %spassByReference_006.php on line %d
201
202Warning: Creating default object from empty value in %spassByReference_006.php on line %d
203
204Warning: Creating default object from empty value in %spassByReference_006.php on line %d
205
206Warning: Creating default object from empty value in %spassByReference_006.php on line %d
207
208Warning: Creating default object from empty value in %spassByReference_006.php on line %d
209
210Warning: Creating default object from empty value in %spassByReference_006.php on line %d
211array(1) {
212  [0]=>
213  string(12) "Ref1 changed"
214}
215array(1) {
216  [0]=>
217  array(1) {
218    [1]=>
219    string(12) "Ref2 changed"
220  }
221}
222object(stdClass)#%d (1) {
223  ["a"]=>
224  string(12) "Ref3 changed"
225}
226object(stdClass)#%d (1) {
227  ["a"]=>
228  object(stdClass)#%d (1) {
229    ["b"]=>
230    string(12) "Ref4 changed"
231  }
232}
233object(stdClass)#%d (1) {
234  ["a"]=>
235  object(stdClass)#%d (1) {
236    ["b"]=>
237    object(stdClass)#%d (1) {
238      ["c"]=>
239      string(12) "Ref5 changed"
240    }
241  }
242}
243