summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/is_callable_variation2.phpt
blob: 1019bca6fabaecf53a5c29820acf88ad028afe2b (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
--TEST--
Test is_callable() function : usage variations - on invalid function names
--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 invalid function names ***\n";
/* check on unset variables */
$unset_var = 10;
unset ($unset_var);

/* opening file resource type */
$file_handle = fopen (__FILE__, "r");

$variants = array (
  NULL,  // NULL as argument
  0,  // zero as argument
  1234567890,  // positive value
  -100123456782,  // negative value
  -2.000000,  // negative float value
  .567,  // positive float value
  FALSE,  // boolean value
  array(1, 2, 3),  // array
  @$unset_var,
  @$undef_var,  //undefined variable
  $file_handle
);

/* use check_iscallable() to check whether given variable is valid function name
 *  expected: false
 */
check_iscallable($variants);

/* closing resources used */
fclose($file_handle);

?>
===DONE===
--EXPECTF--
*** Testing is_callable() on invalid function names ***
-- Iteration  1 --
bool(false)
bool(false)
bool(false)

bool(false)
bool(false)

-- Iteration  2 --
bool(false)
bool(false)
bool(false)
0
bool(false)
bool(false)
0
-- Iteration  3 --
bool(false)
bool(false)
bool(false)
1234567890
bool(false)
bool(false)
1234567890
-- Iteration  4 --
bool(false)
bool(false)
bool(false)
-100123456782
bool(false)
bool(false)
-100123456782
-- Iteration  5 --
bool(false)
bool(false)
bool(false)
-2
bool(false)
bool(false)
-2
-- Iteration  6 --
bool(false)
bool(false)
bool(false)
0.567
bool(false)
bool(false)
0.567
-- Iteration  7 --
bool(false)
bool(false)
bool(false)

bool(false)
bool(false)

-- Iteration  8 --
bool(false)
bool(false)
bool(false)
Array
bool(false)
bool(false)
Array
-- Iteration  9 --
bool(false)
bool(false)
bool(false)

bool(false)
bool(false)

-- Iteration  10 --
bool(false)
bool(false)
bool(false)

bool(false)
bool(false)

-- Iteration  11 --
bool(false)
bool(false)
bool(false)
Resource id #%d
bool(false)
bool(false)
Resource id #%d
===DONE===