php is_function()确定变量是否为函数

问题描述:

我很高兴阅读php中的匿名函数,您声明的函数要比使用 create_function 时要容易的变量声明>.现在,我想知道是否有一个传递了变量的函数,如何检查它以确定它是否是一个函数?还没有is_function()函数,当我对作为函数的变量进行var_dump时::

I was pretty excited to read about anonymous functions in php, which let you declare a variable that is function easier than you could do with create_function. Now I am wondering if I have a function that is passed a variable, how can I check it to determine if it is a function? There is no is_function() function yet, and when I do a var_dump of a variable that is a function::

$func = function(){
    echo 'asdf';
};
var_dump($func);

我明白了:

object(Closure)#8 (0) { } 

关于如何检查这是否是功能的任何想法?

Any thoughts on how to check if this is a function?

使用 is_callable 确定给定变量是否为函数.例如:

Use is_callable to determine whether a given variable is a function. For example:

$func = function()
{  
    echo 'asdf';  
};

if( is_callable( $func ) )
{
    // Will be true.
}