1--TEST--
2Pass uninitialized variables by reference and by value to test implicit initialisation.
3--FILE--
4<?php
5
6function v($val) {
7    $val = "Val changed";
8}
9
10function r(&$ref) {
11    $ref = "Ref changed";
12}
13
14function vv($val1, $val2) {
15    $val1 = "Val1 changed";
16    $val2 = "Val2 changed";
17}
18
19function vr($val, &$ref) {
20    $val = "Val changed";
21    $ref = "Ref changed";
22}
23
24function rv(&$ref, $val) {
25    $val = "Val changed";
26    $ref = "Ref changed";
27}
28
29function rr(&$ref1, &$ref2) {
30    $ref1 = "Ref1 changed";
31    $ref2 = "Ref2 changed";
32}
33
34
35class C {
36    function __construct($val, &$ref) {
37        $val = "Val changed";
38        $ref = "Ref changed";
39    }
40
41    function v($val) {
42        $val = "Val changed";
43    }
44
45    function r(&$ref) {
46        $ref = "Ref changed";
47    }
48
49    function vv($val1, $val2) {
50        $val1 = "Val1 changed";
51        $val2 = "Val2 changed";
52    }
53
54    function vr($val, &$ref) {
55        $val = "Val changed";
56        $ref = "Ref changed";
57    }
58
59    function rv(&$ref, $val) {
60        $val = "Val changed";
61        $ref = "Ref changed";
62    }
63
64    function rr(&$ref1, &$ref2) {
65        $ref1 = "Ref1 changed";
66        $ref2 = "Ref2 changed";
67    }
68
69    static function static_v($val) {
70        $val = "Val changed";
71    }
72
73    static function static_r(&$ref) {
74        $ref = "Ref changed";
75    }
76
77    static function static_vv($val1, $val2) {
78        $val1 = "Val1 changed";
79        $val2 = "Val2 changed";
80    }
81
82    static function static_vr($val, &$ref) {
83        $val = "Val changed";
84        $ref = "Ref changed";
85    }
86
87    static function static_rv(&$ref, $val) {
88        $val = "Val changed";
89        $ref = "Ref changed";
90    }
91
92    static function static_rr(&$ref1, &$ref2) {
93        $ref1 = "Ref1 changed";
94        $ref2 = "Ref2 changed";
95    }
96}
97
98echo "\n ---- Pass by ref / pass by val: functions ----\n";
99unset($u1, $u2);
100v($u1);
101r($u2);
102var_dump($u1, $u2);
103
104unset($u1, $u2);
105vv($u1, $u2);
106var_dump($u1, $u2);
107
108unset($u1, $u2);
109vr($u1, $u2);
110var_dump($u1, $u2);
111
112unset($u1, $u2);
113rv($u1, $u2);
114var_dump($u1, $u2);
115
116unset($u1, $u2);
117rr($u1, $u2);
118var_dump($u1, $u2);
119
120
121echo "\n\n ---- Pass by ref / pass by val: static method calls ----\n";
122unset($u1, $u2);
123C::static_v($u1);
124C::static_r($u2);
125var_dump($u1, $u2);
126
127unset($u1, $u2);
128C::static_vv($u1, $u2);
129var_dump($u1, $u2);
130
131unset($u1, $u2);
132C::static_vr($u1, $u2);
133var_dump($u1, $u2);
134
135unset($u1, $u2);
136C::static_rv($u1, $u2);
137var_dump($u1, $u2);
138
139unset($u1, $u2);
140C::static_rr($u1, $u2);
141var_dump($u1, $u2);
142
143echo "\n\n ---- Pass by ref / pass by val: instance method calls ----\n";
144unset($u1, $u2);
145$c = new C($u1, $u2);
146var_dump($u1, $u2);
147
148unset($u1, $u2);
149$c->v($u1);
150$c->r($u2);
151var_dump($u1, $u2);
152
153unset($u1, $u2);
154$c->vv($u1, $u2);
155var_dump($u1, $u2);
156
157unset($u1, $u2);
158$c->vr($u1, $u2);
159var_dump($u1, $u2);
160
161unset($u1, $u2);
162$c->rv($u1, $u2);
163var_dump($u1, $u2);
164
165unset($u1, $u2);
166$c->rr($u1, $u2);
167var_dump($u1, $u2);
168
169?>
170--EXPECTF--
171---- Pass by ref / pass by val: functions ----
172
173Warning: Undefined variable $u1 in %s on line %d
174
175Warning: Undefined variable $u1 in %s on line %d
176NULL
177string(11) "Ref changed"
178
179Warning: Undefined variable $u1 in %s on line %d
180
181Warning: Undefined variable $u2 in %s on line %d
182
183Warning: Undefined variable $u1 in %s on line %d
184
185Warning: Undefined variable $u2 in %s on line %d
186NULL
187NULL
188
189Warning: Undefined variable $u1 in %s on line %d
190
191Warning: Undefined variable $u1 in %s on line %d
192NULL
193string(11) "Ref changed"
194
195Warning: Undefined variable $u2 in %s on line %d
196
197Warning: Undefined variable $u2 in %s on line %d
198string(11) "Ref changed"
199NULL
200string(12) "Ref1 changed"
201string(12) "Ref2 changed"
202
203
204 ---- Pass by ref / pass by val: static method calls ----
205
206Warning: Undefined variable $u1 in %s on line %d
207
208Warning: Undefined variable $u1 in %s on line %d
209NULL
210string(11) "Ref changed"
211
212Warning: Undefined variable $u1 in %s on line %d
213
214Warning: Undefined variable $u2 in %s on line %d
215
216Warning: Undefined variable $u1 in %s on line %d
217
218Warning: Undefined variable $u2 in %s on line %d
219NULL
220NULL
221
222Warning: Undefined variable $u1 in %s on line %d
223
224Warning: Undefined variable $u1 in %s on line %d
225NULL
226string(11) "Ref changed"
227
228Warning: Undefined variable $u2 in %s on line %d
229
230Warning: Undefined variable $u2 in %s on line %d
231string(11) "Ref changed"
232NULL
233string(12) "Ref1 changed"
234string(12) "Ref2 changed"
235
236
237 ---- Pass by ref / pass by val: instance method calls ----
238
239Warning: Undefined variable $u1 in %s on line %d
240
241Warning: Undefined variable $u1 in %s on line %d
242NULL
243string(11) "Ref changed"
244
245Warning: Undefined variable $u1 in %s on line %d
246
247Warning: Undefined variable $u1 in %s on line %d
248NULL
249string(11) "Ref changed"
250
251Warning: Undefined variable $u1 in %s on line %d
252
253Warning: Undefined variable $u2 in %s on line %d
254
255Warning: Undefined variable $u1 in %s on line %d
256
257Warning: Undefined variable $u2 in %s on line %d
258NULL
259NULL
260
261Warning: Undefined variable $u1 in %s on line %d
262
263Warning: Undefined variable $u1 in %s on line %d
264NULL
265string(11) "Ref changed"
266
267Warning: Undefined variable $u2 in %s on line %d
268
269Warning: Undefined variable $u2 in %s on line %d
270string(11) "Ref changed"
271NULL
272string(12) "Ref1 changed"
273string(12) "Ref2 changed"
274