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