php中oop类,PHP中的OOP:变量中的类函数?

是的,这是可能的,这是知道作为可变函数,有一个

look at this.

PHP官方网站示例:

class Foo

{

function Variable()

{

$name = 'Bar';

$this->$name(); // This calls the Bar() method

}

function Bar()

{

echo "This is Bar";

}

}

$foo = new Foo();

$funcname = "Variable";

$foo->$funcname(); // This calls $foo->Variable()

?>

在你的情况下,确保功能do_the_thing存在。另请注意,您正在存储函数的返回值:

$req = $class->$function_name();

尝试看看变量$ req包含什么。例如这应该给你信息:

print_r($req); // or simple echo as per return value of your function

注意:

可变函数不能与诸如echo(),print(),unset(),isset(),empty(),include(),require()等语言结构一起使用。利用包装函数将这些构造中的任何一个作为可变函数。