【发布时间】:2014-02-28 08:01:30
【问题描述】:
例如:
class Foo() {
const BAR_FUNC = 'bar';
//!!!the following function name needs to use self::BAR_FUNC rather than "hardcoded" text "bar" in the function name
function get_default_bar() {
return 'this is my bar';
}
}
http://au1.php.net/functions.variable-functions 有一个动态命名函数的例子,但它不适用于类方法:
创建并调用动态命名的函数
$tmp = "foo";
$$tmp = function() {
global $tmp;
echo $tmp;
};
$$tmp();
输出“foo”
【问题讨论】:
标签: dynamic