1--TEST--
2Test is_callable() function : usage variations - defined functions
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 * Source code: ext/imap/php_imap.c
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 defined functions ***\n";
30/* function name with simple string */
31function someFunction() {
32}
33
34/* function name with mixed string and integer */
35function x123() {
36}
37
38/* function name as NULL */
39function NULL() {
40}
41
42/* function name with boolean name */
43function false() {
44}
45
46/* function name with string and special character */
47function Hello_World() {
48}
49
50$defined_functions = array (
51  $functionVar1 = 'someFunction',
52  $functionVar2 = 'x123',
53  $functionVar3 = 'NULL',
54  $functionVar4 = 'false',
55  $functionVar5 = "Hello_World"
56);
57/* use check_iscallable() to check whether given string is valid function name
58 *  expected: true as it is valid callback
59 */
60check_iscallable($defined_functions);
61
62?>
63===DONE===
64--EXPECT--
65*** Testing is_callable() on defined functions ***
66-- Iteration  1 --
67bool(true)
68bool(true)
69bool(true)
70someFunction
71bool(true)
72bool(true)
73someFunction
74-- Iteration  2 --
75bool(true)
76bool(true)
77bool(true)
78x123
79bool(true)
80bool(true)
81x123
82-- Iteration  3 --
83bool(true)
84bool(true)
85bool(true)
86NULL
87bool(true)
88bool(true)
89NULL
90-- Iteration  4 --
91bool(true)
92bool(true)
93bool(true)
94false
95bool(true)
96bool(true)
97false
98-- Iteration  5 --
99bool(true)
100bool(true)
101bool(true)
102Hello_World
103bool(true)
104bool(true)
105Hello_World
106===DONE===
107