我需要能够调用一个函数,但函数名存储在一个变量中,这可能吗?例如:
function foo ()
{
//code here
}
function bar ()
{
//code here
}
$functionName = "foo";
// i need to call the function based on what is $functionName
任何帮助都会很棒.
谢谢!
我有一个类,我想用作回调的方法.如何将它们作为参数传递?
Class MyClass {
public function myMethod() {
$this->processSomething(this->myCallback); // How it must be called ?
$this->processSomething(self::myStaticCallback); // How it must be called ?
}
private function processSomething(callable $callback) {
// process something...
$callback();
}
private function myCallback() {
// do something...
}
private static function myStaticCallback() {
// do something...
}
}
Run Code Online (Sandbox Code Playgroud)
UPD:如何从static方法中做同样的事情(什么时候$this不可用)
如何在PHP中动态调用类方法?类方法不是静态的.看起来
call_user_func(...)
Run Code Online (Sandbox Code Playgroud)
仅适用于静态功能?
谢谢.
就像在PHP中的Dynamic类方法调用中的问题一样,我想在Dart中执行此操作.
var = "name";
page.${var} = value;
page.save();
Run Code Online (Sandbox Code Playgroud)
那可能吗?