явное объявление переменных из внешнего скоупа • Не забывать делать это по ссылке • Код становится шумный 1 return function (ConnectionInterface $connection) use ($index, &$clientReceivedFIN, &$clientSentFIN) { 2 $client = $connection; 3 $client->resume(); 4 $client->on('end', function () use ($index, $client, &$clientSentFIN) { 5 $this->loop->addTimer(0.05, function () use ($index, $client, &$clientSentFIN) { 6 $writeResult = $client->write($index); 7 $client->end(); 8 $clientSentFIN++; 9 }); 10 }); 11 $client->on('close', function () use ($index, &$clientReceivedFIN) { 12 $clientReceivedFIN++; 13 }); 14 };