PHP可变函数

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

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

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

posted @ 2016-05-28 10:04  TBHacker  阅读(255)  评论(0编辑  收藏  举报