is_callable()

is_callable() — Verify that a value can be called as a function from the current scope.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

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

Signature

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

Parameters

ParameterTypeWhat it takes
$valuemixedThe value to be checked.
$syntax_onlyboolIf 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, strings, or arrays 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_namestringReceives 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.

Return value

Returns true if value is callable, false otherwise.

Example

A runnable snippet:

function someFunction() {} $functionVariable = 'someFunction'; var_dump(is_callable($functionVariable, false, $callable_name)); var_dump($callable_name);

Output:

bool(true) string(12) "someFunction"

See also

call_user_func(), function_exists(), method_exists()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page is_callable() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.