php call function from string code example
Example 1: php call dynamic function
$vFn = "Login";
$vFn();
call_user_func($vFn, $vars);
abstract class mBase {
public function main() {
.....
}
}
class mA extends mBase {
public function main() {
parent->main();
.....
}
}
class mB extends mBase {
public function main() {
parent->main();
.....
}
}
function runMM(mBase $module) {
$module->main();
}
$m = 'mB';
runMM ($m);
Example 2: php call method from string
class Player {
public function SayHi() { print("Hi"); }
}
$player = new Player();
call_user_func(array($player, 'SayHi'));
$player->{'SayHi'}();
$method = 'SayHi';
$player->$method();