forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic.phpt
More file actions
86 lines (76 loc) · 1.49 KB
/
Copy pathbasic.phpt
File metadata and controls
86 lines (76 loc) · 1.49 KB
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
--TEST--
Basic tests for explicit pass-by-ref
--FILE--
<?php
// Works (by-ref arg)
$a = 42;
incArgRef(&$a);
var_dump($a);
// Works (by-ref arg, deep reference)
writeArgRef(&$b[0][1]);
var_dump($b);
// Works (prefer-ref arg)
$c = 42;
$vars = ['b' => 2, 'a' => 1];
$vars2 = [2, 1];
array_multisort(&$vars, $vars2);
var_dump($vars, $vars2);
// Works (by-ref arg, by-ref function)
$e = 42;
incArgRef(&returnsRef($e));
var_dump($e);
// Fails (by-val arg)
try {
$f = 1;
var_dump(incArgVal(&$f));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
// Fails (by-ref arg, by-val function)
try {
$g = 42;
incArgRef(&returnsVal($g));
var_dump($g);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
// Fails (by-val arg, by-ref function)
try {
$h = 1;
var_dump(incArgVal(&returnsRef($h)));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
// Functions intentionally declared at the end of the file,
// to avoid the fbc being known during compilation
function incArgVal($a) { return $a + 1; }
function incArgRef(&$a) { $a++; }
function writeArgRef(&$a) { $a = 43; }
function returnsVal($a) { return $a; }
function &returnsRef(&$a) { return $a; }
?>
--EXPECT--
int(43)
array(1) {
[0]=>
array(1) {
[1]=>
int(43)
}
}
array(2) {
["a"]=>
int(1)
["b"]=>
int(2)
}
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
int(43)
Cannot pass reference to by-value parameter 1
Cannot pass result of by-value function by reference
Cannot pass reference to by-value parameter 1