Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

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): bool

Parameters

ParameterTypeDescription
$valuemixedThe value to check.
$syntax_onlyboolOptional. Check only the form.
$callable_namestringOptional. 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

In the tutorial

  • More about functions — Named arguments, variable-length argument lists, passing by reference, static variables and recursion in PHP.

Thanks for reading!

Donate to the site — we work hard for you.