Home  >  Article  >  php教程  >  call_user_func函数的注意事项

call_user_func函数的注意事项

WBOY
WBOYOriginal
2016-06-13 11:18:39957browse

 

call_user_func函数的注意事项

parse error: syntax error, unexpected t_list, expecting t_string in

今天在使用这个函数的时候一直提示上述问题。参看官方的手册也没有介绍使用其的注意事项。

附:
mixed call_user_func ( callback $function [, mixed $parameter [, mixed $... ]] )
可以传递任何内置的或者用户自定义的函数,除了语言结构如array(),echo(),empty(),eval(),exit(),isset(),list(),print() 和 unset()。

本人的问题就是在对象中存在一个叫list的方法名。故其和php教程的语言结构list()起冲突了。

看实例应用

call_user_func函数类似于一种特别的调用函数的方法,使用方法如下:    
function  a($b,$c)    
{  
echo  $b;  
echo  $c;  
}  
call_user_func('a',  "111","222");  
call_user_func('a',  "333","444");  
//显示  111  222  333  444  
?>

  

调用类内部的方法比较奇怪,居然用的是array,不知道开发者是如何考虑的,当然省去了new,也是满有新意的:  
class  a  {  
function  b($c)    
{  
echo  $c;  
}  
}  
call_user_func(array("a",  "b"),"111");  
//显示  111  
?>

  

call_user_func_array函数和call_user_func很相似,只不过是换了一种方式传递了参数,让参数的结构更清晰:  
function  a($b,  $c)    
{  
echo  $b;  
echo  $c;

  

}  
call_user_func_array('a',  array("111",  "222"));  
//显示  111  222  
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn