Home php教程 php手册 call_user_func函数的注意事项

call_user_func函数的注意事项

Jun 13, 2016 am 11:18 AM
parse user function Precautions of

 

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 of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Tips for dynamically creating new functions in golang functions

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

Considerations for parameter order in C++ function naming

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

How to write efficient and maintainable functions in Java?

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

Complete collection of excel function formulas

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters Apr 21, 2024 am 10:21 AM

Comparison of the advantages and disadvantages of C++ function default parameters and variable parameters

What are the benefits of C++ functions returning reference types? What are the benefits of C++ functions returning reference types? Apr 20, 2024 pm 09:12 PM

What are the benefits of C++ functions returning reference types?

What is the difference between custom PHP functions and predefined functions? What is the difference between custom PHP functions and predefined functions? Apr 22, 2024 pm 02:21 PM

What is the difference between custom PHP functions and predefined functions?

Advanced usage of reference parameters and pointer parameters in C++ functions Advanced usage of reference parameters and pointer parameters in C++ functions Apr 21, 2024 am 09:39 AM

Advanced usage of reference parameters and pointer parameters in C++ functions

See all articles