1--TEST--
2Test is_callable() function : usage variations - on invalid function names
3--FILE--
4<?php
5/* Prototype: bool is_callable ( mixed $var [, bool $syntax_only [, string &$callable_name]] );
6   Description: Verify that the contents of a variable can be called as a function
7                In case of objects, $var = array($SomeObject, 'MethodName')
8*/
9
10/* Prototype: void check_iscallable( $functions );
11   Description: use iscallable() on given string to check for valid function name
12                returns true if valid function name, false otherwise
13*/
14function check_iscallable( $functions ) {
15  $counter = 1;
16  foreach($functions as $func) {
17    echo "-- Iteration  $counter --\n";
18    var_dump( is_callable($func) );  //given only $var argument
19    var_dump( is_callable($func, TRUE) );  //given $var and $syntax argument
20    var_dump( is_callable($func, TRUE, $callable_name) );
21    echo $callable_name, "\n";
22    var_dump( is_callable($func, FALSE) );  //given $var and $syntax argument
23    var_dump( is_callable($func, FALSE, $callable_name) );
24    echo $callable_name, "\n";
25    $counter++;
26  }
27}
28
29echo "\n*** Testing is_callable() on invalid function names ***\n";
30/* check on unset variables */
31$unset_var = 10;
32unset ($unset_var);
33
34/* opening file resource type */
35$file_handle = fopen (__FILE__, "r");
36
37$variants = array (
38  NULL,  // NULL as argument
39  0,  // zero as argument
40  1234567890,  // positive value
41  -100123456782,  // negative value
42  -2.000000,  // negative float value
43  .567,  // positive float value
44  FALSE,  // boolean value
45  array(1, 2, 3),  // array
46  @$unset_var,
47  @$undef_var,  //undefined variable
48  $file_handle
49);
50
51/* use check_iscallable() to check whether given variable is valid function name
52 *  expected: false
53 */
54check_iscallable($variants);
55
56/* closing resources used */
57fclose($file_handle);
58
59?>
60===DONE===
61--EXPECTF--
62*** Testing is_callable() on invalid function names ***
63-- Iteration  1 --
64bool(false)
65bool(false)
66bool(false)
67
68bool(false)
69bool(false)
70
71-- Iteration  2 --
72bool(false)
73bool(false)
74bool(false)
750
76bool(false)
77bool(false)
780
79-- Iteration  3 --
80bool(false)
81bool(false)
82bool(false)
831234567890
84bool(false)
85bool(false)
861234567890
87-- Iteration  4 --
88bool(false)
89bool(false)
90bool(false)
91-100123456782
92bool(false)
93bool(false)
94-100123456782
95-- Iteration  5 --
96bool(false)
97bool(false)
98bool(false)
99-2
100bool(false)
101bool(false)
102-2
103-- Iteration  6 --
104bool(false)
105bool(false)
106bool(false)
1070.567
108bool(false)
109bool(false)
1100.567
111-- Iteration  7 --
112bool(false)
113bool(false)
114bool(false)
115
116bool(false)
117bool(false)
118
119-- Iteration  8 --
120bool(false)
121bool(false)
122bool(false)
123Array
124bool(false)
125bool(false)
126Array
127-- Iteration  9 --
128bool(false)
129bool(false)
130bool(false)
131
132bool(false)
133bool(false)
134
135-- Iteration  10 --
136bool(false)
137bool(false)
138bool(false)
139
140bool(false)
141bool(false)
142
143-- Iteration  11 --
144bool(false)
145bool(false)
146bool(false)
147Resource id #%d
148bool(false)
149bool(false)
150Resource id #%d
151===DONE===
152