变量函数

 

如果一个变量名后有圆括号,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()
?>

posted @ 2017-06-08 11:01  John_leaf  阅读(296)  评论(0编辑  收藏  举报