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
147 ---- Pass by ref / pass by val: functions ----
148
149Notice: Undefined variable: u1 in %s on line 72
150
151Notice: Undefined variable: u1 in %s on line 74
152NULL
153string(11) "Ref changed"
154
155Notice: Undefined variable: u1 in %s on line 77
156
157Notice: Undefined variable: u2 in %s on line 77
158
159Notice: Undefined variable: u1 in %s on line 78
160
161Notice: Undefined variable: u2 in %s on line 78
162NULL
163NULL
164
165Notice: Undefined variable: u1 in %s on line 81
166
167Notice: Undefined variable: u1 in %s on line 82
168NULL
169string(11) "Ref changed"
170
171Notice: Undefined variable: u2 in %s on line 85
172
173Notice: Undefined variable: u2 in %s on line 86
174string(11) "Ref changed"
175NULL
176string(12) "Ref1 changed"
177string(12) "Ref2 changed"
178
179
180 ---- Pass by ref / pass by val: static method calls ----
181
182Notice: Undefined variable: u1 in %s on line 95
183
184Strict Standards: Non-static method C::v() should not be called statically in %s on line 95
185
186Strict Standards: Non-static method C::r() should not be called statically in %s on line 96
187
188Notice: Undefined variable: u1 in %s on line 97
189NULL
190string(11) "Ref changed"
191
192Notice: Undefined variable: u1 in %s on line 100
193
194Notice: Undefined variable: u2 in %s on line 100
195
196Strict Standards: Non-static method C::vv() should not be called statically in %s on line 100
197
198Notice: Undefined variable: u1 in %s on line 101
199
200Notice: Undefined variable: u2 in %s on line 101
201NULL
202NULL
203
204Notice: Undefined variable: u1 in %s on line 104
205
206Strict Standards: Non-static method C::vr() should not be called statically in %s on line 104
207
208Notice: Undefined variable: u1 in %s on line 105
209NULL
210string(11) "Ref changed"
211
212Notice: Undefined variable: u2 in %s on line 108
213
214Strict Standards: Non-static method C::rv() should not be called statically in %s on line 108
215
216Notice: Undefined variable: u2 in %s on line 109
217string(11) "Ref changed"
218NULL
219
220Strict Standards: Non-static method C::rr() should not be called statically in %s on line 112
221string(12) "Ref1 changed"
222string(12) "Ref2 changed"
223
224
225 ---- Pass by ref / pass by val: instance method calls ----
226
227Notice: Undefined variable: u1 in %s on line 117
228
229Notice: Undefined variable: u1 in %s on line 118
230NULL
231string(11) "Ref changed"
232
233Notice: Undefined variable: u1 in %s on line 121
234
235Notice: Undefined variable: u1 in %s on line 123
236NULL
237string(11) "Ref changed"
238
239Notice: Undefined variable: u1 in %s on line 126
240
241Notice: Undefined variable: u2 in %s on line 126
242
243Notice: Undefined variable: u1 in %s on line 127
244
245Notice: Undefined variable: u2 in %s on line 127
246NULL
247NULL
248
249Notice: Undefined variable: u1 in %s on line 130
250
251Notice: Undefined variable: u1 in %s on line 131
252NULL
253string(11) "Ref changed"
254
255Notice: Undefined variable: u2 in %s on line 134
256
257Notice: Undefined variable: u2 in %s on line 135
258string(11) "Ref changed"
259NULL
260string(12) "Ref1 changed"
261string(12) "Ref2 changed"