blob: 19b59fea9600a5c22c2b80a8e9a9769cc1d18d38 (
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
|
--TEST--
Test get_defined_vars() function
--FILE--
<?php
/* Prototype: array get_defined_vars ( void )
Description: This function returns a multidimensional array containing a list of all defined
variables, be them environment, server or user-defined variables, within the scope that
get_defined_vars() is called.
*/
echo "Simple testcase for get_defined_vars() function\n\n";
function f1() {
echo "\n-- Function f1() called --\n";
$vars = get_defined_vars();
if (count($vars) != 0) {
echo "TEST FAILED\n";
}
echo "\n-- ..define some local variables --\n";
$i = 123;
$f = 123.456;
$b = false;
$s = "Hello World";
$arr = array(1,2,3,4);
var_dump( get_defined_vars() );
f2();
}
function f2() {
echo "\n -- Function f2() called --\n";
$vars= get_defined_vars();
if (count($vars) != 0) {
echo "TEST FAILED\n";
}
echo "\n-- ...define some variables --\n";
$i = 456;
$f = 456.678;
$b = true;
$s = "Goodnight";
$arr = array("foo", "bar");
var_dump( get_defined_vars() );
echo "\n-- ...define some more variables --\n";
$i1 = 456;
$f1 = 456.678;
$b1 = true;
var_dump( get_defined_vars() );
}
echo "\n-- Get variables at global scope --\n";
$vars = get_defined_vars();
if (count($vars) == 0) {
echo "TEST FAILED - Global variables missing at global scope\n";
}
// call a function
f1();
?>
--EXPECT--
Simple testcase for get_defined_vars() function
-- Get variables at global scope --
-- Function f1() called --
-- ..define some local variables --
array(6) {
["vars"]=>
array(0) {
}
["i"]=>
int(123)
["f"]=>
float(123.456)
["b"]=>
bool(false)
["s"]=>
string(11) "Hello World"
["arr"]=>
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
}
}
-- Function f2() called --
-- ...define some variables --
array(6) {
["vars"]=>
array(0) {
}
["i"]=>
int(456)
["f"]=>
float(456.678)
["b"]=>
bool(true)
["s"]=>
string(9) "Goodnight"
["arr"]=>
array(2) {
[0]=>
string(3) "foo"
[1]=>
string(3) "bar"
}
}
-- ...define some more variables --
array(9) {
["vars"]=>
array(0) {
}
["i"]=>
int(456)
["f"]=>
float(456.678)
["b"]=>
bool(true)
["s"]=>
string(9) "Goodnight"
["arr"]=>
array(2) {
[0]=>
string(3) "foo"
[1]=>
string(3) "bar"
}
["i1"]=>
int(456)
["f1"]=>
float(456.678)
["b1"]=>
bool(true)
}
|