Skip to content

Commit c5b25c0

Browse files
Use str_increment() to fix PHP 8.5 deprecation
1 parent bd97bc9 commit c5b25c0

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/EventLoop/Internal/AbstractDriver.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ public function queue(\Closure $closure, mixed ...$args): void
141141

142142
public function defer(\Closure $closure): string
143143
{
144-
$deferCallback = new DeferCallback($this->nextId++, $closure);
144+
$id = $this->nextId;
145+
$this->nextId = \PHP_VERSION_ID >= 80300 ? str_increment($this->nextId) : 1 + $this->nextId;
146+
$deferCallback = new DeferCallback($id, $closure);
145147

146148
$this->callbacks[$deferCallback->id] = $deferCallback;
147149
$this->enableDeferQueue[$deferCallback->id] = $deferCallback;
@@ -155,7 +157,9 @@ public function delay(float $delay, \Closure $closure): string
155157
throw new \Error("Delay must be greater than or equal to zero");
156158
}
157159

158-
$timerCallback = new TimerCallback($this->nextId++, $delay, $closure, $this->now() + $delay);
160+
$id = $this->nextId;
161+
$this->nextId = \PHP_VERSION_ID >= 80300 ? str_increment($this->nextId) : 1 + $this->nextId;
162+
$timerCallback = new TimerCallback($id, $delay, $closure, $this->now() + $delay);
159163

160164
$this->callbacks[$timerCallback->id] = $timerCallback;
161165
$this->enableQueue[$timerCallback->id] = $timerCallback;
@@ -169,7 +173,9 @@ public function repeat(float $interval, \Closure $closure): string
169173
throw new \Error("Interval must be greater than or equal to zero");
170174
}
171175

172-
$timerCallback = new TimerCallback($this->nextId++, $interval, $closure, $this->now() + $interval, true);
176+
$id = $this->nextId;
177+
$this->nextId = \PHP_VERSION_ID >= 80300 ? str_increment($this->nextId) : 1 + $this->nextId;
178+
$timerCallback = new TimerCallback($id, $interval, $closure, $this->now() + $interval, true);
173179

174180
$this->callbacks[$timerCallback->id] = $timerCallback;
175181
$this->enableQueue[$timerCallback->id] = $timerCallback;
@@ -179,7 +185,9 @@ public function repeat(float $interval, \Closure $closure): string
179185

180186
public function onReadable(mixed $stream, \Closure $closure): string
181187
{
182-
$streamCallback = new StreamReadableCallback($this->nextId++, $closure, $stream);
188+
$id = $this->nextId;
189+
$this->nextId = \PHP_VERSION_ID >= 80300 ? str_increment($this->nextId) : 1 + $this->nextId;
190+
$streamCallback = new StreamReadableCallback($id, $closure, $stream);
183191

184192
$this->callbacks[$streamCallback->id] = $streamCallback;
185193
$this->enableQueue[$streamCallback->id] = $streamCallback;
@@ -189,7 +197,9 @@ public function onReadable(mixed $stream, \Closure $closure): string
189197

190198
public function onWritable($stream, \Closure $closure): string
191199
{
192-
$streamCallback = new StreamWritableCallback($this->nextId++, $closure, $stream);
200+
$id = $this->nextId;
201+
$this->nextId = \PHP_VERSION_ID >= 80300 ? str_increment($this->nextId) : 1 + $this->nextId;
202+
$streamCallback = new StreamWritableCallback($id, $closure, $stream);
193203

194204
$this->callbacks[$streamCallback->id] = $streamCallback;
195205
$this->enableQueue[$streamCallback->id] = $streamCallback;
@@ -199,7 +209,9 @@ public function onWritable($stream, \Closure $closure): string
199209

200210
public function onSignal(int $signal, \Closure $closure): string
201211
{
202-
$signalCallback = new SignalCallback($this->nextId++, $closure, $signal);
212+
$id = $this->nextId;
213+
$this->nextId = \PHP_VERSION_ID >= 80300 ? str_increment($this->nextId) : 1 + $this->nextId;
214+
$signalCallback = new SignalCallback($id, $closure, $signal);
203215

204216
$this->callbacks[$signalCallback->id] = $signalCallback;
205217
$this->enableQueue[$signalCallback->id] = $signalCallback;

0 commit comments

Comments
 (0)