In PHP, is_callable() checks whether a value can be called like a function. It returns true for function names, closures and valid method callbacks, and false otherwise.
This is useful before you pass a callback to functions such as array_map() or call_user_func(). The function checks that the name exists and that the method is reachable from where you call it. Private methods, for example, are not callable from outside the class.
Syntax
Call is_callable() with the values you need. Start with this line.
PHP
$result = is_callable($value);
Call
What it does
is_callable('strlen')
Returns true, because strlen() is a real function.
is_callable([$object, 'method'])
Returns true if the method exists and can be called from here.
is_callable($value, true, $name)
Checks only the syntax and also stores the callable's name in $name.
A callable can be a function name string, a closure, an invokable object, a [$object, 'method'] pair, a 'Class::method' string or a first-class callable such as strlen(...). With the second argument set to true, PHP only checks that the value looks like a callable.
The string 'hello' matches the function we declared, so it is callable.
'strlen' is a built-in function, so it is callable too.
An arrow function is a Closure object, which is always callable.
'no_such_function' does not exist, so the result is false.
Example 2 — Methods and Visibility
Methods are checked using an array or a Class::method string. Visibility matters.
PHP
<?php
class Greeter {
public function hi() { return "Hi"; }
public static function hello() { return "Hello"; }
private function secret() { return "Secret"; }
}
$g = new Greeter();
var_dump(is_callable([$g, 'hi']));
var_dump(is_callable('Greeter::hello'));
var_dump(is_callable([$g, 'secret']));
var_dump(is_callable([$g, 'missing']));
Output
bool(true)
bool(true)
bool(false)
bool(false)
How It Works
[$g, 'hi'] points to a public method, so it is callable.
'Greeter::hello' is a public static method, so the string form works too.
secret() is private, so it cannot be called from outside the class and the result is false.
'missing' is not declared in the class, so the result is false.
Example 3 — Syntax Only and Callable Name
The optional arguments let you check only the shape of a value and read back its name.
PHP
<?php
class Greeter {
public function hi() { return "Hi"; }
}
is_callable([new Greeter(), 'hi'], false, $name);
echo $name, PHP_EOL;
var_dump(is_callable('Greeter::nope', true));
var_dump(is_callable('Greeter::nope'));
Output
Greeter::hi
bool(true)
bool(false)
How It Works
The third argument is passed by reference, so is_callable() writes the callable's name into $name.
echo prints Greeter::hi, which is the class and method name.
With syntax_only set to true, 'Greeter::nope' is accepted because it has a valid Class::method shape.
Without that flag, PHP checks that the method exists, and the result is false.
Frequently Asked Questions
is_callable() returns true if a value can be called as a function. That includes function names, closures, invokable objects and valid method callbacks.
function_exists() only checks for a named function. is_callable() also handles closures, object methods, static methods and invokable objects, so it is more general.
method_exists() checks if a method is declared, even if it is private. is_callable() also checks whether you are allowed to call it from the current place, so private methods return false from outside.
When it is true, PHP only checks that the value has a valid shape, such as a string or a [class, method] pair. It does not check that the function or method exists.
Use it when a callback comes from outside your code, such as a setting or a parameter, and you want to fail early with a clear message instead of getting an error later.