@@ -42,13 +42,13 @@ final class ExtLibeventLoop implements LoopInterface
4242 private $ timerCallback ;
4343 private $ timerEvents ;
4444 private $ streamCallback ;
45- private $ readEvents = [] ;
46- private $ writeEvents = [] ;
47- private $ readListeners = [] ;
48- private $ writeListeners = [] ;
45+ private $ readEvents = array () ;
46+ private $ writeEvents = array () ;
47+ private $ readListeners = array () ;
48+ private $ writeListeners = array () ;
4949 private $ running ;
5050 private $ signals ;
51- private $ signalEvents = [] ;
51+ private $ signalEvents = array () ;
5252
5353 public function __construct ()
5454 {
@@ -228,24 +228,26 @@ private function scheduleTimer(TimerInterface $timer)
228228 */
229229 private function createTimerCallback ()
230230 {
231- $ this ->timerCallback = function ($ _ , $ __ , $ timer ) {
231+ $ that = $ this ;
232+ $ timers = $ this ->timerEvents ;
233+ $ this ->timerCallback = function ($ _ , $ __ , $ timer ) use ($ timers , $ that ) {
232234 call_user_func ($ timer ->getCallback (), $ timer );
233235
234236 // Timer already cancelled ...
235- if (!$ this -> timerEvents ->contains ($ timer )) {
237+ if (!$ timers ->contains ($ timer )) {
236238 return ;
237239 }
238240
239241 // Reschedule periodic timers ...
240242 if ($ timer ->isPeriodic ()) {
241243 event_add (
242- $ this -> timerEvents [$ timer ],
243- $ timer ->getInterval () * self ::MICROSECONDS_PER_SECOND
244+ $ timers [$ timer ],
245+ $ timer ->getInterval () * ExtLibeventLoop ::MICROSECONDS_PER_SECOND
244246 );
245247
246248 // Clean-up one shot timers ...
247249 } else {
248- $ this ->cancelTimer ($ timer );
250+ $ that ->cancelTimer ($ timer );
249251 }
250252 };
251253 }
@@ -259,15 +261,17 @@ private function createTimerCallback()
259261 */
260262 private function createStreamCallback ()
261263 {
262- $ this ->streamCallback = function ($ stream , $ flags ) {
264+ $ read =& $ this ->readListeners ;
265+ $ write =& $ this ->writeListeners ;
266+ $ this ->streamCallback = function ($ stream , $ flags ) use (&$ read , &$ write ) {
263267 $ key = (int ) $ stream ;
264268
265- if (EV_READ === (EV_READ & $ flags ) && isset ($ this -> readListeners [$ key ])) {
266- call_user_func ($ this -> readListeners [$ key ], $ stream );
269+ if (EV_READ === (EV_READ & $ flags ) && isset ($ read [$ key ])) {
270+ call_user_func ($ read [$ key ], $ stream );
267271 }
268272
269- if (EV_WRITE === (EV_WRITE & $ flags ) && isset ($ this -> writeListeners [$ key ])) {
270- call_user_func ($ this -> writeListeners [$ key ], $ stream );
273+ if (EV_WRITE === (EV_WRITE & $ flags ) && isset ($ write [$ key ])) {
274+ call_user_func ($ write [$ key ], $ stream );
271275 }
272276 };
273277 }
0 commit comments