• PHP Video Tutorials

PHP - is_callable() Function


Advertisements

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

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements