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