将函数绑定到php 5.3中的变量有什么好处[重复]

This question already has an answer here:

$test = function(){};

It's a new feature of php ver 5.3. I'm interested to know what's the reason.

</div>

This is called variable functions in php. We can define some functions and can assign it into variables.This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth.

<?php
function foo() {
    echo "In foo()<br />
";
}

function bar($arg = '')
{
    echo "In bar(); argument was '$arg'.<br />
";
}

// 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

Check these too