-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathFunctionWithReferenceFixture.php
107 lines (97 loc) · 3.2 KB
/
FunctionWithReferenceFixture.php
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
<?php
function /*comment*/ &function_with_return_by_reference_and_param($param) {
echo $param;
return $param;
}
function function_with_static_var() {
static $static1,
$static_num = 12,
$static_neg_num = -1.5, // Unused variable $static_neg_num
$static_string = 'abc', // Unused variable $static_string
$static_string2 = "def", // Unused variable $static_string2
$static_define = MYDEFINE, // Unused variable $static_define
$static_constant = MyClass::CONSTANT, // Unused variable $static_constant
$static2,
$static_new_unused = new Foobar(), // Unused variable $static_new_unused
$static_new = new Foobar();
static $static_heredoc = <<<END_OF_HEREDOC
this is an ugly but valid way to continue after a heredoc
END_OF_HEREDOC
, $static3;
static $static_nowdoc = <<<'END_OF_NOWDOC'
this is an ugly but valid way to continue after a nowdoc
END_OF_NOWDOC
, $static4;
echo $static1;
echo $static_num;
echo $static2;
echo $var; // Undefined variable $var
echo $static_heredoc;
echo $static3;
echo $static_nowdoc;
echo $static4 . $static_new;
}
function function_with_pass_by_reference_param(&$param) {
echo $param;
}
function function_with_pass_by_reference_calls() {
echo $matches; // Undefined variable $matches
echo $needle; // Undefined variable $needle
echo $haystack; // Undefined variable $haystack
preg_match('/(abc)/', 'defabcghi', /* comment */ $matches);
preg_match(
$needle, // Undefined variable $needle
'defabcghi',
$matches
);
preg_match(
'/(abc)/',
$haystack, // Undefined variable $haystack
$matches
);
echo $matches;
echo $needle; // Undefined variable $needle
echo $haystack; // Undefined variable $haystack
$stmt = 'whatever';
$var1 = 'one';
$var2 = 'two';
echo $var1;
echo $var2;
echo $var3; // Undefined variable $var3
maxdb_stmt_bind_result /*comment*/ ($stmt, $var1, $var2, $var3);
echo $var1;
echo $var2;
echo $var3;
}
function function_with_pass_by_ref_assign_only_arg(& /*comment*/ $return_value) {
$return_value = 42;
}
function function_with_ignored_reference_call() {
$foo = 'bar';
my_reference_function($foo, $baz, $bip); // Undefined variable $bar, Undefined variable $bip
another_reference_function($foo, $foo2, $foo3); // Undefined variable $foo2, Undefined variable $foo3
}
function function_with_wordpress_reference_calls() {
wp_parse_str('foo=bar', $vars); // Undefined variable $vars
}
function function_with_array_walk($userNameParts) {
array_walk($userNameParts, function (string &$value): void {
if (strlen($value) <= 3) {
return;
}
$value = ucfirst($value);
});
}
function function_with_foreach_with_reference($derivatives, $base_plugin_definition) {
foreach ($derivatives as &$entry) {
$entry .= $base_plugin_definition;
}
foreach ($derivatives as &$unused) { // Unused variable $unused
$base_plugin_definition .= '1';
}
return $derivatives;
}
function function_with_ignored_reference_call_with_namespace() {
$foo = 'bar';
\My\Functions\my_reference_function($foo, $baz, $bip); // Undefined variable $bar, Undefined variable $bip
}