PHP Function Is_Callable
PHP’s is_callable function determines whether a variable’s callable function exists and can be called. This is an especially useful function in object-oriented programming where a lot of code is encapsulated in methods that can be called from other classes. Using is_callable can help prevent errors from trying to call functions that don’t exist.
When calling is_callable() you can pass it two parameters – the first is the variable to test and the second is an optional parameter that specifies if you want to only check the syntax of the callable name, or if you also want to make sure that the callable exists in code and can be called. When you set the second parameter to false, is_callable will only check if the callable name can be stored in the input variable, e.g. it could be a string or an array that contains an object and a method name. It will still reject simple variables that are not strings and an array that doesn’t have a valid structure.
You can use is_callable together with the function_exists() function to check for class methods that are not visible from the current scope, i.e private or protected methods. This is not something that can be done with the method_exists() function alone since it will return true for all methods regardless of their visibility. I wrote about this issue in a previous post.