我已经尝试过有和没有{}的代码,但它一直说"语法错误,意外的'{',期望标识符(T_STRING(在..">
$page = $_GET['page'];
$do = $_GET['do'];
{$page}::{$do}();
然后我有一个类和该类中的一个函数,应该被调用,看起来像这样。
class Example {
public static function index()
{}
}
因此,如果 $page = "示例" 并且 $do = "索引",我想调用 example::index((;
有两种方法可以做到这一点:
//$class: the class which contains your static function
//$method: the function you want to call
call_user_func("$class::$method");
//OR
call_user_func(array($class, $method));
在您的情况下:
call_user_func("$page::$do");
或
call_user_func(array($page, $do));