Using a callback function in a class in PHP

Source: Internet
Author: User
Recently in the study of the object-oriented programming of PHP, the idea of object-oriented thinking in solving complex problems really play a huge role, can not imagine if the StarCraft game is not used in the development of object-oriented thinking is how complex. The object-oriented idea is indeed a significant advance in the history of computer programming methods.

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);

It 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.