call_user_func函数的注意事项
Jun 13, 2016 am 11:18 AM
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
?>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Tips for dynamically creating new functions in golang functions

Considerations for parameter order in C++ function naming

How to write efficient and maintainable functions in Java?

Complete collection of excel function formulas

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 is the difference between custom PHP functions and predefined functions?

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