File: is_callable_variation1.phpt

package info (click to toggle)
php5 5.6.33%2Bdfsg-0%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 157,872 kB
  • sloc: ansic: 756,065; php: 22,030; sh: 12,311; cpp: 8,771; xml: 6,179; yacc: 1,564; exp: 1,514; makefile: 1,467; pascal: 1,147; awk: 538; perl: 315; sql: 22
file content (208 lines) | stat: -rw-r--r-- 3,416 bytes parent folder | download | duplicates (6)
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
--TEST--
Test is_callable() function : usage variations - undefined functions
--INI--
precision=14
error_reporting = E_ALL & ~E_NOTICE | E_STRICT
--FILE--
<?php
/* Prototype: bool is_callable ( mixed $var [, bool $syntax_only [, string &$callable_name]] );
   Description: Verify that the contents of a variable can be called as a function
                In case of objects, $var = array($SomeObject, 'MethodName')
*/

/* Prototype: void check_iscallable( $functions );
   Description: use iscallable() on given string to check for valid function name
                returns true if valid function name, false otherwise
*/
function check_iscallable( $functions ) {
  $counter = 1;
  foreach($functions as $func) {
    echo "-- Iteration  $counter --\n";
    var_dump( is_callable($func) );  //given only $var argument
    var_dump( is_callable($func, TRUE) );  //given $var and $syntax argument
    var_dump( is_callable($func, TRUE, $callable_name) );
    echo $callable_name, "\n";
    var_dump( is_callable($func, FALSE) );  //given $var and $syntax argument
    var_dump( is_callable($func, FALSE, $callable_name) );
    echo $callable_name, "\n";
    $counter++;
  }
}

echo "\n*** Testing is_callable() on undefined functions ***\n";
$undef_functions = array (
  "",  //empty string
  '',
  " ",  //string with a space
  ' ',
  "12356",
  "\0",
  '\0',
  "hello world",
  'hello world',
  "welcome\0",
  'welcome\0',
  "==%%%***$$$@@@!!",
  "false",
  "\070",
  '\t',  //escape character
  '\007',
  '123',
  'echo()'
);

/* use check_iscallable() to check whether given string is valid function name
 * expected: true with $syntax = TRUE
 *           false with $syntax = FALSE
 */
check_iscallable($undef_functions);

?>
===DONE===
--EXPECTF--
*** Testing is_callable() on undefined functions ***
-- Iteration  1 --
bool(false)
bool(true)
bool(true)

bool(false)
bool(false)

-- Iteration  2 --
bool(false)
bool(true)
bool(true)

bool(false)
bool(false)

-- Iteration  3 --
bool(false)
bool(true)
bool(true)
 
bool(false)
bool(false)
 
-- Iteration  4 --
bool(false)
bool(true)
bool(true)
 
bool(false)
bool(false)
 
-- Iteration  5 --
bool(false)
bool(true)
bool(true)
12356
bool(false)
bool(false)
12356
-- Iteration  6 --
bool(false)
bool(true)
bool(true)

bool(false)
bool(false)

-- Iteration  7 --
bool(false)
bool(true)
bool(true)
\0
bool(false)
bool(false)
\0
-- Iteration  8 --
bool(false)
bool(true)
bool(true)
hello world
bool(false)
bool(false)
hello world
-- Iteration  9 --
bool(false)
bool(true)
bool(true)
hello world
bool(false)
bool(false)
hello world
-- Iteration  10 --
bool(false)
bool(true)
bool(true)
welcome
bool(false)
bool(false)
welcome
-- Iteration  11 --
bool(false)
bool(true)
bool(true)
welcome\0
bool(false)
bool(false)
welcome\0
-- Iteration  12 --
bool(false)
bool(true)
bool(true)
==%%%***$$$@@@!!
bool(false)
bool(false)
==%%%***$$$@@@!!
-- Iteration  13 --
bool(false)
bool(true)
bool(true)
false
bool(false)
bool(false)
false
-- Iteration  14 --
bool(false)
bool(true)
bool(true)
8
bool(false)
bool(false)
8
-- Iteration  15 --
bool(false)
bool(true)
bool(true)
\t
bool(false)
bool(false)
\t
-- Iteration  16 --
bool(false)
bool(true)
bool(true)
\007
bool(false)
bool(false)
\007
-- Iteration  17 --
bool(false)
bool(true)
bool(true)
123
bool(false)
bool(false)
123
-- Iteration  18 --
bool(false)
bool(true)
bool(true)
echo()
bool(false)
bool(false)
echo()
===DONE===