1--TEST-- 2Test is_callable() function : usage variations - defined functions 3--INI-- 4precision=14 5error_reporting = E_ALL & ~E_NOTICE | E_STRICT 6--FILE-- 7<?php 8/* Prototype: bool is_callable ( mixed $var [, bool $syntax_only [, string &$callable_name]] ); 9 * Description: Verify that the contents of a variable can be called as a function 10 * Source code: ext/imap/php_imap.c 11 */ 12 13/* Prototype: void check_iscallable( $functions ); 14 Description: use iscallable() on given string to check for valid function name 15 returns true if valid function name, false otherwise 16*/ 17function check_iscallable( $functions ) { 18 $counter = 1; 19 foreach($functions as $func) { 20 echo "-- Iteration $counter --\n"; 21 var_dump( is_callable($func) ); //given only $var argument 22 var_dump( is_callable($func, TRUE) ); //given $var and $syntax argument 23 var_dump( is_callable($func, TRUE, $callable_name) ); 24 echo $callable_name, "\n"; 25 var_dump( is_callable($func, FALSE) ); //given $var and $syntax argument 26 var_dump( is_callable($func, FALSE, $callable_name) ); 27 echo $callable_name, "\n"; 28 $counter++; 29 } 30} 31 32echo "\n*** Testing is_callable() on defined functions ***\n"; 33/* function name with simple string */ 34function someFunction() { 35} 36 37/* function name with mixed string and integer */ 38function x123() { 39} 40 41/* function name as NULL */ 42function NULL() { 43} 44 45/* function name with boolean name */ 46function false() { 47} 48 49/* function name with string and special character */ 50function Hello_World() { 51} 52 53$defined_functions = array ( 54 $functionVar1 = 'someFunction', 55 $functionVar2 = 'x123', 56 $functionVar3 = 'NULL', 57 $functionVar4 = 'false', 58 $functionVar5 = "Hello_World" 59); 60/* use check_iscallable() to check whether given string is valid function name 61 * expected: true as it is valid callback 62 */ 63check_iscallable($defined_functions); 64 65?> 66===DONE=== 67--EXPECT-- 68*** Testing is_callable() on defined functions *** 69-- Iteration 1 -- 70bool(true) 71bool(true) 72bool(true) 73someFunction 74bool(true) 75bool(true) 76someFunction 77-- Iteration 2 -- 78bool(true) 79bool(true) 80bool(true) 81x123 82bool(true) 83bool(true) 84x123 85-- Iteration 3 -- 86bool(true) 87bool(true) 88bool(true) 89NULL 90bool(true) 91bool(true) 92NULL 93-- Iteration 4 -- 94bool(true) 95bool(true) 96bool(true) 97false 98bool(true) 99bool(true) 100false 101-- Iteration 5 -- 102bool(true) 103bool(true) 104bool(true) 105Hello_World 106bool(true) 107bool(true) 108Hello_World 109===DONE=== 110