我会建议call_user_func()
或call_user_func_array
PHP方法。 你可以在这里查看(call_user_func_array,call_user_func)。
例如
class Foo {
static public function test() {
print "Hello world!\n";
}
}
call_user_func('Foo::test');//FOO is the class, test is the method both separated by ::
//or
call_user_func(array('Foo', 'test'));//alternatively you can pass the class and method as an array
如果你有要传递到方法参数,然后使用call_user_func_array()
功能。
示例。
class foo {
function bar($arg, $arg2) {
echo __METHOD__, " got $arg and $arg2\n";
}
}
// Call the $foo->bar() method with 2 arguments
call_user_func_array(array("foo", "bar"), array("three", "four"));
//or
//FOO is the class, bar is the method both separated by ::
call_user_func_array("foo::bar"), array("three", "four"));
这就是我该怎么做的。请注意,从内部类可以使用父母和自我。 – Ross 2009-02-10 20:55:14
非常感谢。 – 2009-02-10 20:57:06
在类似的笔记上,你也可以做$ var ='Name'; $ OBJ - > { '得到'。是$ var}(); – Mario 2009-02-10 21:04:51