变量函数

如果一个变量名后有圆括号,php 将寻找与变量的值同名的函数,并且将尝试执行它。

<?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()
?>

原文地址:https://www.cnblogs.com/John-/p/6961735.html