php支持变量做函数名,如:
$func=’print_r’;
$func(‘hello’);
相当于print_r(‘hello’); 这种特性在处理一些问题时比较有用,但是在类中时,如果用类似的写法就会有问题,如:
$this->func=’print_r’;
$this->func(‘hello’);
这时会提示函数func未定义。这种情况下要使用call_user_func_array($this->func, $argv)。
php支持变量做函数名,如:
$func=’print_r’;
$func(‘hello’);
相当于print_r(‘hello’); 这种特性在处理一些问题时比较有用,但是在类中时,如果用类似的写法就会有问题,如:
$this->func=’print_r’;
$this->func(‘hello’);
这时会提示函数func未定义。这种情况下要使用call_user_func_array($this->func, $argv)。
Recent Comments