<?php
$worker = new Worker();
$worker->onWorkerStart = function()
{
for ($i=1; $i<=10; $i++){
global $data_connection;
$data_connection= $i;
$a = new AsyncTcpConnection('XXX');
// 建立连接
$con->onConnect = function($connection) {
global $data_connection;
$connection->send($data_connection);}
}
}
Worker::runAll();
$connection->send($data_connection)的时候 $data_connection无法取出正确值
怎么样赋值才可以全局变量
将包含global关键字的行代码删除,然后onConnect回调改为: