Introduction: In PHP provides a powerful system functions to help us complete the function, but sometimes only the system function is often not enough, but also need to encapsulate custom functions according to the business, "PHP Advanced-function Video Tutorial" explains how to customize functions, as well as custom functions common problems, PHP is a must-see course.
Course Play Address: http://www.php.cn/course/417.html
The teacher's lecture style:
The teacher lively image, witty witty, witty, touching. A vivid image of the metaphor, like the finishing touch, to the students to open the door of wisdom, a proper sense of humor, attracting students to smile, such as drinking a cup of glycol wine, to the aftertaste and nostalgia, the philosopher's motto, culture of the proverbs from time and again interspersed in the middle, give people to think and alert.
The difficulty in this video is the use of callback functions in PHP:
callback function, closure in JS is not unfamiliar, JS use it can complete the event mechanism, a lot of complex operations. PHP is not used very often, today to say a PHP in the callback function and anonymous functions.
callback function
callback function: Callback (that is, call and back is returned to the main function after being called by the main function), refers to a piece of executable code that passes through the function arguments to other code.
The popular explanation is that the function is passed into another function as a parameter, and there are many functions in PHP that require parameters as functions, like Array_map,usort,call_user_func_array, they execute the incoming function and return the result directly to the main function. The advantage is that the function is easy to use as a value, and the code is concise and readable.
Today in the class method that you create to call another class method as its callback function, I would like to write directly in the callback function where the name of another class method directly, but has been an error saying "Invalid Parameters", and then a thought is not to use the Self keyword to try, the result is reported this error. I do not know what to do, check the Chinese manual has not found a solution, and then carefully read the PHP official website manual, this manual has to solve the problem of the grammar.
Class utils{public function Array_or ($input) { return array_reduce ($input, Array (' utils ', ' Sum '), 0);
} public function sum ($v, $w) { return $v + = $w; } } $uti = new Utils; $a = array (1,2,3,4,5); echo $uti->array_or ($a);
The
makes me wonder why calling another class method would be in the form of an array, as if it were more appropriate to use the Self keyword, and I really don't know what they are thinking about designing such a grammar. However, I think that since the design of others must have his reason, but I have not realized this truth.