Skip to content

Commit 143445e

Browse files
committed
[3.x] Fix SPL SplObjectStorage deprecations
in PHP8.5 the SplObjectStorage::contains, SplObjectStorage::attach, and SplObjectStorage::detach methods have been deprecated through https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_splobjectstoragecontains_splobjectstorageattach_and_splobjectstoragedetach
1 parent d1a83a2 commit 143445e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/ExtEvLoop.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ public function addTimer($interval, $callback)
141141
$callback = function () use ($timer) {
142142
\call_user_func($timer->getCallback(), $timer);
143143

144-
if ($this->timers->contains($timer)) {
144+
if ($this->timers->offsetExists($timer)) {
145145
$this->cancelTimer($timer);
146146
}
147147
};
148148

149149
$event = $this->loop->timer($timer->getInterval(), 0.0, $callback);
150-
$this->timers->attach($timer, $event);
150+
$this->timers->offsetSet($timer, $event);
151151

152152
return $timer;
153153
}
@@ -161,7 +161,7 @@ public function addPeriodicTimer($interval, $callback)
161161
};
162162

163163
$event = $this->loop->timer($timer->getInterval(), $timer->getInterval(), $callback);
164-
$this->timers->attach($timer, $event);
164+
$this->timers->offsetSet($timer, $event);
165165

166166
return $timer;
167167
}
@@ -174,7 +174,7 @@ public function cancelTimer(TimerInterface $timer)
174174

175175
$event = $this->timers[$timer];
176176
$event->stop();
177-
$this->timers->detach($timer);
177+
$this->timers->offsetUnset($timer);
178178
}
179179

180180
public function futureTick($listener)

src/ExtEventLoop.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __destruct()
6464
{
6565
// explicitly clear all references to Event objects to prevent SEGFAULTs on Windows
6666
foreach ($this->timerEvents as $timer) {
67-
$this->timerEvents->detach($timer);
67+
$this->timerEvents->offsetUnset($timer);
6868
}
6969

7070
$this->readEvents = [];
@@ -153,9 +153,9 @@ public function addPeriodicTimer($interval, $callback)
153153

154154
public function cancelTimer(TimerInterface $timer)
155155
{
156-
if ($this->timerEvents->contains($timer)) {
156+
if ($this->timerEvents->offsetExists($timer)) {
157157
$this->timerEvents[$timer]->free();
158-
$this->timerEvents->detach($timer);
158+
$this->timerEvents->offsetUnset($timer);
159159
}
160160
}
161161

@@ -238,7 +238,7 @@ private function createTimerCallback()
238238
$this->timerCallback = function ($_, $__, $timer) {
239239
\call_user_func($timer->getCallback(), $timer);
240240

241-
if (!$timer->isPeriodic() && $this->timerEvents->contains($timer)) {
241+
if (!$timer->isPeriodic() && $this->timerEvents->offsetExists($timer)) {
242242
$this->cancelTimer($timer);
243243
}
244244
};

src/ExtUvLoop.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ public function addTimer($interval, $callback)
117117
$callback = function () use ($timer) {
118118
\call_user_func($timer->getCallback(), $timer);
119119

120-
if ($this->timers->contains($timer)) {
120+
if ($this->timers->offsetExists($timer)) {
121121
$this->cancelTimer($timer);
122122
}
123123
};
124124

125125
$event = \uv_timer_init($this->uv);
126-
$this->timers->attach($timer, $event);
126+
$this->timers->offsetSet($timer, $event);
127127
\uv_timer_start(
128128
$event,
129129
$this->convertFloatSecondsToMilliseconds($interval),
@@ -147,7 +147,7 @@ public function addPeriodicTimer($interval, $callback)
147147

148148
$interval = $this->convertFloatSecondsToMilliseconds($interval);
149149
$event = \uv_timer_init($this->uv);
150-
$this->timers->attach($timer, $event);
150+
$this->timers->offsetSet($timer, $event);
151151
\uv_timer_start(
152152
$event,
153153
$interval,
@@ -165,7 +165,7 @@ public function cancelTimer(TimerInterface $timer)
165165
{
166166
if (isset($this->timers[$timer])) {
167167
@\uv_timer_stop($this->timers[$timer]);
168-
$this->timers->detach($timer);
168+
$this->timers->offsetUnset($timer);
169169
}
170170
}
171171

0 commit comments

Comments
 (0)