Esempio n. 1
0
    }
}
echo "\n*** Testing is_callable() on defined functions ***\n";
/* function name with simple string */
function someFunction()
{
}
/* function name with mixed string and integer */
function x123()
{
}
/* function name as NULL */
function NULL()
{
}
/* function name with boolean name */
function false()
{
}
/* function name with string and special character */
function Hello_World()
{
}
$defined_functions = array($functionVar1 = 'someFunction', $functionVar2 = 'x123', $functionVar3 = 'NULL', $functionVar4 = 'false', $functionVar5 = "Hello_World");
/* use check_iscallable() to check whether given string is valid function name
 *  expected: true as it is valid callback
 */
check_iscallable($defined_functions);
?>
===DONE===
Esempio n. 2
0
   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("", '', " ", ' ', "12356", "", '\\0', "hello world", 'hello world', "welcome", 'welcome\\0', "==%%%***\$\$\$@@@!!", "false", "8", '\\t', '\\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===
Esempio n. 3
0
    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, 0, 1234567890, -100123456782, -2.0, 0.5669999999999999, FALSE, array(1, 2, 3), @$unset_var, @$undef_var, $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===