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

请用一个例子解释,PHP如何动态的建立一个function。explainwiththehelpofanexample,howcanafunctionbedynamica... 请用一个例子解释,PHP如何动态的建立一个function。
explain with the help of an example, how can a function be dynamically created in PHP?

如果是英文答案就更好了
展开
 我来答
eachcan
2008-06-29 · 超过48用户采纳过TA的回答
知道小有建树答主
回答量:127
采纳率:0%
帮助的人:81.3万
展开全部
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;
}

$func = 'foo';
$func(); // This calls foo()

$func = 'bar';
$func('test'); // This calls bar()

$func = 'echoit';
$func('test'); // This calls echoit()
?>

You can create a function also,and do it as follow:
Creates an anonymous function from the parameters passed, and returns a unique name for it.

<?php
$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');
echo "New anonymous function: $newfunc\n";
echo $newfunc(2, M_E) . "\n";
// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599
?>

Any questions are welcomed to me.
什么不知道知道
2008-06-30
知道答主
回答量:7
采纳率:0%
帮助的人:0
展开全部
小鬼回答正确,小鬼的站内论坛就是PHP写的,也很棒,只是想给小鬼提个问题,你的论坛自带的博客系统似乎有点问题吧?
评论似乎不能显示,(或者是要在后台设置显示的吗?)评论部分有些编码似乎也失控了吧?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式