is_callable
Checks whether a value can be called as a function.
Syntax
is_callable(mixed $value, bool $syntax_only = false, string &$callable_name = null): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | The value to check. |
| $syntax_only | bool | Optional. Check only the form. |
| $callable_name | string | Optional. Receives the function name. |
Return value
bool`true` if the value is callable.
Examples
A function name, a closure and a plain string:
<?php
var_dump(is_callable('strlen'));
var_dump(is_callable(fn () => 1));
var_dump(is_callable('no_such_function'));Output:
bool(true)
bool(true)
bool(false)Notes
An array [$object, 'method'] is callable too if the method exists and is accessible.
See also
- function_exists — Checks whether a function is defined.
- method_exists — Checks whether a class or an object has a method.
- call_user_func — Calls a function held in a variable.
In the tutorial
- More about functions — Named arguments, variable-length argument lists, passing by reference, static variables and recursion in PHP.