PHP可变函数

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

function bar($arg = '') {
    echo "In bar() argument was '$arg' 
";
}

// 使用 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()

$func = "test"; // This calls test() but not have test()
$func('test');
?> 

输出:

In foo()
In bar() argument was 'test'
test
Fatal error: Call to undefined function test()

原文地址:https://www.cnblogs.com/jiqing9006/p/5536875.html