【发布时间】:2014-01-07 15:43:58
【问题描述】:
我有以下设置:
class test {
public static function something() {
$somethingElseFunction = "somethingElse";
// How can I call the method with the name saved in variable?
}
public static function somethingElse($a) {
echo 'bla';
}
}
如何使用变量调用函数? (函数名称在变量中)。 我还需要为它做一个 function_exists()。
试过这个:
if (function_exists(self::$somethingElseFunction ())) {
if (!call_user_func(self::$somethingElseFunction , $a)) {
}
}
没用。
【问题讨论】:
-
不重复...在一个类中...如果是单独的我可以使用 call_user_func
-
尽可能避免静态是个好主意;)
-
完美...全部...所有答案都可以调用...有关function_exists的任何帮助(不能使用任何sintax)? @Anyone 不是当你真的希望它是静态的;)。
-
你要使用
method_exists();!
标签: php class static class-method