Home > Backend Development > PHP Tutorial > Precautions for using the call_user_func function in PHP, calluserfunc_PHP tutorial

Precautions for using the call_user_func function in PHP, calluserfunc_PHP tutorial

WBOY
Release: 2016-07-13 10:13:34
Original
993 people have browsed it

Notes on using the call_user_func function in php, calluserfunc

The example in this article describes the precautions for using the call_user_func function in PHP. Share it with everyone for your reference. The specific analysis is as follows:

Notes on the call_user_func function: parse error: syntax error, unexpected t_list, expecting t_string in. When using this function today, I kept getting prompted with the above problem. The official manual did not introduce the precautions for using it.

Attachment: mixed call_user_func(callback $function [, mixed $parameter [, mixed $... ]]). You can pass any built-in or user-defined function, except language structures such as array(), echo() ,empty(),eval(),exit(),isset(),list(),print() and unset().

My problem is that there is a method name called list in the object, so it conflicts with the language structure list() of the PHP tutorial.

Look at the example application: the call_user_func function is similar to a special method of calling a function. The usage method is as follows:

Copy code The code is as follows:
function a($b,$c)
{ 
echo $b;
echo $c;

call_user_func('a', "111","222");
call_user_func('a', "333","444");
//Display 111 222 333 444

It is strange to call the method inside the class. It actually uses array. I don’t know what the developer thought about it. Of course, new is omitted, which is also very innovative. The code is as follows:
Copy code The code is as follows:
class a { 
function b($c)
{ 
echo $c;


call_user_func(array("a", "b"),"111");
//Display 111

The call_user_func_array function is very similar to call_user_func, except that the parameters are passed in a different way to make the structure of the parameters clearer. The code is as follows:
Copy code The code is as follows:
function a($b, $c)
{ 
echo $b;
echo $c;

call_user_func_array('a', array("111", "222"));
//Display 111 222

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/915428.htmlTechArticlePrecautions for using the call_user_func function in php, calluserfunc This article describes the precautions for using the call_user_func function in php. Share it with everyone for your reference. The specific analysis is as follows:...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template