Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

is_callable

Description

The is_callable of Variable Handling for PHP verify that the contents of a variable can be called as a function.

Syntax

is_callable(
    mixed $value,
    bool $syntax_only = false,
    string &$callable_name = null
): bool

Parameters

value

The value to check

syntax_only

If set to true the function only verifies that value might be a function or method. It will only reject simple variables that are not strings, or an array that does not have a valid structure to be used as a callback. The valid ones are supposed to have only 2 entries, the first of which is an object or a string, and the second a string.

callable_name

Receives the "callable name".

Return

Returns true if value is callable, false otherwise.

Examples

1 · value · function

<?

function myfunction()
{
}

$value = "myfunction";

$return = is_callable($value);

var_export($return);

?>
true

2 · value · method

<?

class myclass
{
    function myfunction()
    {
    }
}

$value = [new myclass, "myfunction"];

$return = is_callable($value);

var_export($return);

?>
true

3 · syntax_only · function

<?

function myfunction()
{
}

$value = "myfunction";
$syntax_only = true;

$return = is_callable($value, $syntax_only);

var_export($return);

?>
true

4 · syntax_only · method

<?

class myclass
{
    function myfunction()
    {
    }
}

$value = [new myclass, "myfunction"];
$syntax_only = true;

$return = is_callable($value, $syntax_only);

var_export($return);

?>
true

5 · callable_name · function

<?

function myfunction()
{
}

$value = "myfunction";
$syntax_only = true;

$return = is_callable($value, $syntax_only, $callable_name);

var_export($return);
echo PHP_EOL . $callable_name;

?>
true
myfunction

6 · callable_name · method

<?

class myclass
{
    function myfunction()
    {
    }
}

$value = [new myclass, "myfunction"];
$syntax_only = true;

$return = is_callable($value, $syntax_only, $callable_name);

var_export($return);
echo PHP_EOL . $callable_name;

?>
true
myclass::myfunction
HomeMenu