is_callable

Verify that a value can be called as a function from the current scope

&reftitle.description; `bool` `is_callable` `mixed` `value` `bool` `syntax_only`&false; `string` `callable_name`&null;

Verifies that `value` is a `callable`, or that it can be called using the `call_user_func` function.

&reftitle.parameters;

`value`

- The value to be checked.

`syntax_only`

- If set to &true; the function only verifies that `value` might be a function or method. It will reject any values that are not invokable objects, `Closure`, &string;s, or &array;s that do not have a valid structure to be used as a callback. A valid callable array has 2 entries, the first of which is an object or a string, and the second a string.

`callable_name`

- Receives the "callable name", e.g. `"SomeClass::someMethod"`. Note, however, that despite the implication that `SomeClass::someMethod()` is a callable static method, this is not the case.

&reftitle.returnvalues;

Returns &true; if `value` is callable, &false; otherwise.

&reftitle.examples;

### Checking whether a string can be called as a function

    <?php

    function someFunction() {}

    $functionVariable = 'someFunction';

    var_dump(is_callable($functionVariable, false, $callable_name));

    var_dump($callable_name);

    ?>

&example.outputs;

    bool(true)
    string(12) "someFunction"

### Checking whether an array can be called as a function

    <?php

    class SomeClass
    {
        public function someMethod() {}
    }

    $anObject = new SomeClass();

    $methodVariable = [$anObject, 'someMethod'];

    var_dump(is_callable($methodVariable, true, $callable_name));

    var_dump($callable_name);

    ?>

&example.outputs;

    bool(true)
    string(21) "SomeClass::someMethod"

### `is_callable` and constructors

`is_callable` reports constructors as not being callable.

    <?php

    class Foo
    {
        public function __construct() {}

        public function foo() {}
    }

    var_dump(
        is_callable(['Foo', '__construct']),
        is_callable(['Foo', 'foo'])
    );

    ?>

&example.outputs;

    bool(false)
    bool(false)

&reftitle.notes;

- An object is always callable if it implements __invoke(), and that method is visible in the current scope.
- A class name is callable if it implements __callStatic().
- If an object implements __call(), then this function will return &true; for any method on that object, even if the method is not defined.
- This function may trigger autoloading if called with the name of a class.

&reftitle.seealso;

- `call_user_func`
- `function_exists`
- `method_exists`