PHP | Check if a variable is a function Last Updated : 05 Mar, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report To determine whether a passed argument is a function or not, Few of the most preferred methods are shown below. Using is_callable() Function: It is an inbuilt function in PHP which is used to verify the contents of a variable in called as a function. It can check that a simple variable contains the name of a valid function, or that an array contains a properly encoded object and function name. Syntax: bool is_callable ( $var_name, $syntx_only, $calbl_name ) Parameters: The is_callable() function accepts three parameters as shown in above syntax and are described below. It depends on user to use how many parameters one, two or three. $var_name: The name of a function stored in a string variable $var_name, or an object and the name of a method within the object. $syntx_only: If it set to TRUE the function only verifies that name might be a function or method. It will 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. $calbl_name: It receives the callable name. This option only implemented for classes. Return Value: This function returns a boolean type value. It returns TRUE if $var_name is callable, FALSE otherwise. Example: This example uses is_callable() function to verify whether the parameter is a function or not. php <?php // Declare a variable and initialize // with function $function = function() { echo 'GeeksForGeeks'; }; // Check is_callable function contains // function or not if( is_callable( $function ) ) { echo "It is function"; } else { echo "It is not function"; } // Declare a variable and // initialize it $var = "GeeksForGeeks"; echo "\n"; // Check is_callable function contains // function or not if( is_callable( $var ) ) { echo "It is function"; } else { echo "It is not function"; } ?> Output: It is function It is not function instanceof: The instanceof operator in PHP is used to find out if an object is an instantiated instance of a class. Syntax: $f instanceof Class_Name Operands: It contains two operands which are listed below: $f: It is used as an object. Class_Name: It is used to hold the class name. Return Value: It returns True if the object is of this class or has this class as one of its parents else it will return a False value. Example: This example use instanceof operator to determine if a variable is a function in PHP. php <?php // Declare a variable and initialize // with function $func = function() { echo 'GeeksforGeeks'; }; // Use instanceof to check it contains // function or not if($func instanceof Closure) { echo "function"; } else { echo "not a function"; } // Declare a variable and initialize it $var = "GFG"; echo "\n"; // Use instanceof to check it contains // function or not if($var instanceof Closure) { echo "function"; } else{ echo "not a function"; } ?> Output: function not a function Example: This example uses function_exist() and is_object() methods to check whether an argument is a function or not. php <?php // Declare a function function myFun() { echo 'GeeksforGeeks'; }; // Determine if a variable is a function function is_function($func) { return (is_string($func) && function_exists($func)) || (is_object($func) && ($func instanceof Closure)); } echo is_function('myFun'); ?> Output: 1 Comment More infoAdvertise with us Next Article PHP | Check if a variable is a function P PranchalKatiyar Follow Improve Article Tags : Web Technologies PHP PHP Programs PHP-function Similar Reads How to check Whether a Variable is Null in PHP? We are given a variable and the task is to check whether the value of the given variable is null or not and returns a Boolean value using PHP. To check a variable is null or not, we use is_null() function. A variable is considered to be NULL if it does not store any value. It returns TRUE if the val 1 min read PHP trait_exists() Function PHP implements a way to reuse code called Traits. The trait_exists() function in PHP is an inbuilt function that is used to check whether a trait exists or not. This function accepts the traitname and autoload as parameters and returns true if trait exists, false if not, null in case of an error. Sy 2 min read How to check whether a variable is set or not using PHP ? We have given a variable and the task is to check whether a variable var is set or not in PHP. In order to do this task, we have the following methods in PHP: Approach 1: Using isset() Method: The isset() method returns True if the variable is declared and its value is not equal to NULL. Syntax: boo 2 min read What is the difference between is_a() function and instanceof in PHP? is_a() Function The is_a() is a built-in function in PHP which is used to check whether a given object is of a given class or not. It also checks if the given class is one of the parents of the given object or not. Syntax: bool is_a( $object, $class_name, $allow_string ) Parameters: This function ac 3 min read How to check whether an array is empty using PHP? Arrays are commonly used data structures that can hold multiple values. Sometimes it is necessary to check if an array is empty or not, and it is an important task to avoid errors when working with data. PHP offers several easy and effective ways to check if an array is empty. Below are the most com 3 min read Like