• PHP Video Tutorials

PHP - is_callable() Function



Definition and Usage

The function is_callable() checks whether contents of a variable can be called as a function.

Syntax

bool is_callable ( mixed $value , bool $syntax_only = false , string &$callable_name = null )

Parameters

Sr.No Parameter & Description
1

value

Mandatory. The value to be verified

2

syntax_only

Optional. If set to true the function only verifies that value might be a function or method. It will only reject simple variables that are not strings, or an array that does not have a valid structure to be used as a callback. The valid ones are supposed to have only 2 entries, the first of which is an object or a string, and the second a string.

3

callable_name

Optional. Returns a callable name (only for classes)

Return Values

This function returns a boolean type value. Returns true if value is callable, false otherwise.

Dependencies

PHP 4.0.6 and above

Example

Following example demonstrates how to check a variable to see if it can be called as a function −

<?php
   function testFunction(){
   }
   $functionVariable = 'testFunction';
   var_dump(is_callable($functionVariable, false, $callable_name));   // bool(true)
   echo $callable_name. "<br>";   // testFunction
   // using only-one parameter
   var_dump(is_callable($functionVariable));
?>

Output

This will produce following result −

bool(true) testFunction
bool(true)
php_variable_handling_functions.htm
Advertisements