summaryrefslogtreecommitdiff
path: root/tests/lang/passByReference_005.phpt
blob: dc32962d67a982f6bfc0e43209ebe3be890464ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
--TEST--
Pass uninitialised variables by reference and by value to test implicit initialisation.
--FILE--
<?php

function v($val) {
  $val = "Val changed";
}

function r(&$ref) {
  $ref = "Ref changed";
}


function vv($val1, $val2) {
  $val1 = "Val1 changed";
  $val2 = "Val2 changed";
}

function vr($val, &$ref) {
  $val = "Val changed";
  $ref = "Ref changed";
}

function rv(&$ref, $val) {
  $val = "Val changed";
  $ref = "Ref changed";
}

function rr(&$ref1, &$ref2) {
  $ref1 = "Ref1 changed";
  $ref2 = "Ref2 changed";
}


class C {

	function __construct($val, &$ref) {
	  $val = "Val changed";
	  $ref = "Ref changed";
	}

	function v($val) {
	  $val = "Val changed";
	}

	function r(&$ref) {
	  $ref = "Ref changed";
	}

	function vv($val1, $val2) {
	  $val1 = "Val1 changed";
	  $val2 = "Val2 changed";
	}

	function vr($val, &$ref) {
	  $val = "Val changed";
	  $ref = "Ref changed";
	}

	function rv(&$ref, $val) {
	  $val = "Val changed";
	  $ref = "Ref changed";
	}

	function rr(&$ref1, &$ref2) {
	  $ref1 = "Ref1 changed";
	  $ref2 = "Ref2 changed";
	}

}

echo "\n ---- Pass by ref / pass by val: functions ----\n";
unset($u1, $u2);
v($u1);
r($u2);
var_dump($u1, $u2);

unset($u1, $u2);
vv($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
vr($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
rv($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
rr($u1, $u2);
var_dump($u1, $u2);


echo "\n\n ---- Pass by ref / pass by val: static method calls ----\n";
unset($u1, $u2);
C::v($u1);
C::r($u2);
var_dump($u1, $u2);

unset($u1, $u2);
C::vv($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
C::vr($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
C::rv($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
C::rr($u1, $u2);
var_dump($u1, $u2);

echo "\n\n ---- Pass by ref / pass by val: instance method calls ----\n";
unset($u1, $u2);
$c = new C($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
$c->v($u1);
$c->r($u2);
var_dump($u1, $u2);

unset($u1, $u2);
$c->vv($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
$c->vr($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
$c->rv($u1, $u2);
var_dump($u1, $u2);

unset($u1, $u2);
$c->rr($u1, $u2);
var_dump($u1, $u2);

?>
--EXPECTF--
---- Pass by ref / pass by val: functions ----

Notice: Undefined variable: u1 in %s on line 72

Notice: Undefined variable: u1 in %s on line 74
NULL
string(11) "Ref changed"

Notice: Undefined variable: u1 in %s on line 77

Notice: Undefined variable: u2 in %s on line 77

Notice: Undefined variable: u1 in %s on line 78

Notice: Undefined variable: u2 in %s on line 78
NULL
NULL

Notice: Undefined variable: u1 in %s on line 81

Notice: Undefined variable: u1 in %s on line 82
NULL
string(11) "Ref changed"

Notice: Undefined variable: u2 in %s on line 85

Notice: Undefined variable: u2 in %s on line 86
string(11) "Ref changed"
NULL
string(12) "Ref1 changed"
string(12) "Ref2 changed"


 ---- Pass by ref / pass by val: static method calls ----

Deprecated: Non-static method C::v() should not be called statically in %s on line 95

Notice: Undefined variable: u1 in %s on line 95

Deprecated: Non-static method C::r() should not be called statically in %s on line 96

Notice: Undefined variable: u1 in %s on line 97
NULL
string(11) "Ref changed"

Deprecated: Non-static method C::vv() should not be called statically in %s on line 100

Notice: Undefined variable: u1 in %s on line 100

Notice: Undefined variable: u2 in %s on line 100

Notice: Undefined variable: u1 in %s on line 101

Notice: Undefined variable: u2 in %s on line 101
NULL
NULL

Deprecated: Non-static method C::vr() should not be called statically in %s on line 104

Notice: Undefined variable: u1 in %s on line 104

Notice: Undefined variable: u1 in %s on line 105
NULL
string(11) "Ref changed"

Deprecated: Non-static method C::rv() should not be called statically in %s on line 108

Notice: Undefined variable: u2 in %s on line 108

Notice: Undefined variable: u2 in %s on line 109
string(11) "Ref changed"
NULL

Deprecated: Non-static method C::rr() should not be called statically in %s on line 112
string(12) "Ref1 changed"
string(12) "Ref2 changed"


 ---- Pass by ref / pass by val: instance method calls ----

Notice: Undefined variable: u1 in %s on line 117

Notice: Undefined variable: u1 in %s on line 118
NULL
string(11) "Ref changed"

Notice: Undefined variable: u1 in %s on line 121

Notice: Undefined variable: u1 in %s on line 123
NULL
string(11) "Ref changed"

Notice: Undefined variable: u1 in %s on line 126

Notice: Undefined variable: u2 in %s on line 126

Notice: Undefined variable: u1 in %s on line 127

Notice: Undefined variable: u2 in %s on line 127
NULL
NULL

Notice: Undefined variable: u1 in %s on line 130

Notice: Undefined variable: u1 in %s on line 131
NULL
string(11) "Ref changed"

Notice: Undefined variable: u2 in %s on line 134

Notice: Undefined variable: u2 in %s on line 135
string(11) "Ref changed"
NULL
string(12) "Ref1 changed"
string(12) "Ref2 changed"