有没有办法为 PHP 动态调用同一类中的方法?我没有正确的语法,但我想做类似的事情:
$this->{$methodName}($arg1, $arg2, $arg3);
最佳答案
有不止一种方法可以做到这一点:
$this->{$methodName}($arg1, $arg2, $arg3);
$this->$methodName($arg1, $arg2, $arg3);
call_user_func_array(array($this, $methodName), array($arg1, $arg2, $arg3));
您甚至可以使用反射 API http://php.net/manual/en/class.reflection.php
关于php - PHP中的动态类方法调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/251485/