English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP is_callable() function usage and example

PHP available functions

is_callable() The function is used to check if a function is callable in the current environment.

is_callable() The function verifies whether the content of the variable can be called as a function. This can check variables containing valid function names, or an array that contains correctly encoded objects and function names.

PHP version requirement: PHP 4 >= 4.0.6, PHP 5, PHP 7

Syntax

bool is_callable ( callable $name [, bool $syntax_only = false [, string &$callable_name ]] )

Parameter description:

  • $name: the callback function to check.
  • $syntax_only: if set to TRUE, this function only verifies that the name may be a function or method. It only rejects non-strings or structures that do not contain valid callback function elements. Valid should contain two elements, the first is an object or character, and the second is a character.
  • $callable_name: accepts "callable name".

Return value

If the name is callable, it returns TRUE, otherwise it returns FALSE...

Online example

<?php
//  Check if the variable is a callable function 
function someFunction() 
{
}
$functionVariable = 'someFunction';
var_dump(is_callable($functionVariable, false, $callable_name));  // bool(true)
echo $callable_name, "\n";  // someFunction
//
//  The array contains a method
//
class someClass {
    function someMethod() 
    {
    }
}
$anObject = new someClass();
$methodVariable = array($anObject, 'someMethod');
var_dump(is_callable($methodVariable, true, $callable_name));  //  bool(true)
echo $callable_name, "\n";  //  someClass::someMethod
?>

The output result is:

bool(true)
someFunction
bool(true)
someClass::someMethod

PHP available functions