$test = function(){};这是php版本5.3的一个新特性。我很想知道原因是什么。
发布于 2014-02-19 18:51:02
这在php中称为变量函数。我们可以定义一些函数,并将其赋值到variables.This中,这意味着如果变量名后面附加了括号,PHP将查找与变量计算结果相同的函数,并尝试执行它。除此之外,它还可用于实现回调、函数表等。
<?php
function foo() {
echo "In foo()<br />\n";
}
function bar($arg = '')
{
echo "In bar(); argument was '$arg'.<br />\n";
}
// This is a wrapper function around echo
function echoit($string)
{
echo $string;
}
$func = 'foo';
$func(); // This calls foo()
$func = 'bar';
$func('test'); // This calls bar()
$func = 'echoit';
$func('test'); // This calls echoit()
?>Source
https://stackoverflow.com/questions/21878182
复制相似问题