Easy Tutorial
❮ Func String Substr Func Xml Set Character Data Handler ❯

PHP is_callable() Function

PHP Available Functions

The is_callable() function is used to verify whether a function can be called in the current environment.

The is_callable() function checks if the contents of a variable can be called as a function. This can verify a variable containing a valid function name or an array containing an object and a method name.

PHP Version Requirements: PHP 4 >= 4.0.6, PHP 5, PHP 7

Syntax

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

Parameter Descriptions:

Return Value

Returns TRUE if the name is callable, otherwise FALSE.

Example

<?php
// Check if a variable is a callable function

function someFunction() 
{
}

$functionVariable = 'someFunction';

var_dump(is_callable($functionVariable, false, $callable_name));  // bool(true)

echo $callable_name, "\n";  // someFunction

//
// Array containing 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

?>

Output:

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

PHP Available Functions

❮ Func String Substr Func Xml Set Character Data Handler ❯