What does the use after the function in WorkerMan mean?

Source: Internet
Author: User
For example, there is a piece of code in the example: {code...}. for example, there is a piece of code in the example:

$ Recv_worker-> onMessage = function ($ connection, $ data) use ($ recv_worker) {foreach ($ recv_worker-> sendWorker-> connections as $ send_connection) {// $ send_connection-> websocketType = "\ x82"; $ send_connection-> send ($ data) ;}}; function ($ connection, $ data) why can use ($ recv_worker) be followed by function instead of directly writing function body {}? In addition, how is the callback function... = function () {} implemented? As long as there is a similar usage in js, it seems that this usage is not seen in php before.

Reply content:

For example, there is a piece of code in the example:

$ Recv_worker-> onMessage = function ($ connection, $ data) use ($ recv_worker) {foreach ($ recv_worker-> sendWorker-> connections as $ send_connection) {// $ send_connection-> websocketType = "\ x82"; $ send_connection-> send ($ data) ;}}; function ($ connection, $ data) why can use ($ recv_worker) be followed by function instead of directly writing function body {}? In addition, how is the callback function... = function () {} implemented? As long as there is a similar usage in js, it seems that this usage is not seen in php before.

This is called an anonymous function.
Http://www.php.net/manual/zh...
Let's take a look at the official instructions... which are common in js... this is a feature after php5.3.
Use is used to pass external output to an anonymous function or closure.

There may not be many places in the web framework that the subject is exposed to for the time being...

Php closure

Common features

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.