@@ -43,15 +43,14 @@ public static function get()
4343 $ hasRun = true ;
4444 });
4545
46- $ stopped =& self ::$ stopped ;
47- register_shutdown_function (function () use ($ loop , &$ hasRun , &$ stopped ) {
46+ register_shutdown_function (function () use ($ loop , &$ hasRun ) {
4847 // Don't run if we're coming from a fatal error (uncaught exception).
4948 $ error = error_get_last ();
50- if ((isset ( $ error ['type ' ]) ? $ error [ ' type ' ] : 0 ) & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR )) {
49+ if (($ error ['type ' ] ?? 0 ) & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR )) {
5150 return ;
5251 }
5352
54- if (!$ hasRun && !$ stopped ) {
53+ if (!$ hasRun && !self :: $ stopped ) {
5554 $ loop ->run ();
5655 }
5756 });
@@ -83,11 +82,7 @@ public static function set(LoopInterface $loop)
8382 */
8483 public static function addReadStream ($ stream , $ listener )
8584 {
86- // create loop instance on demand (legacy PHP < 7 doesn't like ternaries in method calls)
87- if (self ::$ instance === null ) {
88- self ::get ();
89- }
90- self ::$ instance ->addReadStream ($ stream , $ listener );
85+ (self ::$ instance ?? self ::get ())->addReadStream ($ stream , $ listener );
9186 }
9287
9388 /**
@@ -101,11 +96,7 @@ public static function addReadStream($stream, $listener)
10196 */
10297 public static function addWriteStream ($ stream , $ listener )
10398 {
104- // create loop instance on demand (legacy PHP < 7 doesn't like ternaries in method calls)
105- if (self ::$ instance === null ) {
106- self ::get ();
107- }
108- self ::$ instance ->addWriteStream ($ stream , $ listener );
99+ (self ::$ instance ?? self ::get ())->addWriteStream ($ stream , $ listener );
109100 }
110101
111102 /**
@@ -146,11 +137,7 @@ public static function removeWriteStream($stream)
146137 */
147138 public static function addTimer ($ interval , $ callback )
148139 {
149- // create loop instance on demand (legacy PHP < 7 doesn't like ternaries in method calls)
150- if (self ::$ instance === null ) {
151- self ::get ();
152- }
153- return self ::$ instance ->addTimer ($ interval , $ callback );
140+ return (self ::$ instance ?? self ::get ())->addTimer ($ interval , $ callback );
154141 }
155142
156143 /**
@@ -163,11 +150,7 @@ public static function addTimer($interval, $callback)
163150 */
164151 public static function addPeriodicTimer ($ interval , $ callback )
165152 {
166- // create loop instance on demand (legacy PHP < 7 doesn't like ternaries in method calls)
167- if (self ::$ instance === null ) {
168- self ::get ();
169- }
170- return self ::$ instance ->addPeriodicTimer ($ interval , $ callback );
153+ return (self ::$ instance ?? self ::get ())->addPeriodicTimer ($ interval , $ callback );
171154 }
172155
173156 /**
@@ -193,12 +176,7 @@ public static function cancelTimer(TimerInterface $timer)
193176 */
194177 public static function futureTick ($ listener )
195178 {
196- // create loop instance on demand (legacy PHP < 7 doesn't like ternaries in method calls)
197- if (self ::$ instance === null ) {
198- self ::get ();
199- }
200-
201- self ::$ instance ->futureTick ($ listener );
179+ (self ::$ instance ?? self ::get ())->futureTick ($ listener );
202180 }
203181
204182 /**
@@ -211,12 +189,7 @@ public static function futureTick($listener)
211189 */
212190 public static function addSignal ($ signal , $ listener )
213191 {
214- // create loop instance on demand (legacy PHP < 7 doesn't like ternaries in method calls)
215- if (self ::$ instance === null ) {
216- self ::get ();
217- }
218-
219- self ::$ instance ->addSignal ($ signal , $ listener );
192+ (self ::$ instance ?? self ::get ())->addSignal ($ signal , $ listener );
220193 }
221194
222195 /**
@@ -242,12 +215,7 @@ public static function removeSignal($signal, $listener)
242215 */
243216 public static function run ()
244217 {
245- // create loop instance on demand (legacy PHP < 7 doesn't like ternaries in method calls)
246- if (self ::$ instance === null ) {
247- self ::get ();
248- }
249-
250- self ::$ instance ->run ();
218+ (self ::$ instance ?? self ::get ())->run ();
251219 }
252220
253221 /**
0 commit comments