在线等 高手帮忙 关于PHP的问题

来源:百度知道 编辑:UC知道 时间:2024/05/06 04:38:30
请用一个例子解释,PHP如何动态的建立一个function。
explain with the help of an example, how can a function be dynamically created in PHP?

如果是英文答案就更好了

PHP supports the concept of variable functions. 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.

Variable functions won't work with language constructs such as echo(), print(), unset(), isset(), empty(), include(), require() and the like. Utilize wrapper functions to make use of any of these constructs as variable functions.

Example #1 Variable function example

<?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;
}

$