Skip to content

Commit abb89a1

Browse files
committed
[1.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 489d5f5 commit abb89a1

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
@@ -143,13 +143,13 @@ public function addTimer($interval, $callback)
143143
$callback = function () use ($timer, $timers, $that) {
144144
\call_user_func($timer->getCallback(), $timer);
145145

146-
if ($timers->contains($timer)) {
146+
if ($timers->offsetExists($timer)) {
147147
$that->cancelTimer($timer);
148148
}
149149
};
150150

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

154154
return $timer;
155155
}
@@ -163,7 +163,7 @@ public function addPeriodicTimer($interval, $callback)
163163
};
164164

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

168168
return $timer;
169169
}
@@ -176,7 +176,7 @@ public function cancelTimer(TimerInterface $timer)
176176

177177
$event = $this->timers[$timer];
178178
$event->stop();
179-
$this->timers->detach($timer);
179+
$this->timers->offsetUnset($timer);
180180
}
181181

182182
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 = array();
@@ -157,9 +157,9 @@ public function addPeriodicTimer($interval, $callback)
157157

158158
public function cancelTimer(TimerInterface $timer)
159159
{
160-
if ($this->timerEvents->contains($timer)) {
160+
if ($this->timerEvents->offsetExists($timer)) {
161161
$this->timerEvents[$timer]->free();
162-
$this->timerEvents->detach($timer);
162+
$this->timerEvents->offsetUnset($timer);
163163
}
164164
}
165165

@@ -243,7 +243,7 @@ private function createTimerCallback()
243243
$this->timerCallback = function ($_, $__, $timer) use ($timers) {
244244
\call_user_func($timer->getCallback(), $timer);
245245

246-
if (!$timer->isPeriodic() && $timers->contains($timer)) {
246+
if (!$timer->isPeriodic() && $timers->offsetExists($timer)) {
247247
$this->cancelTimer($timer);
248248
}
249249
};

src/ExtUvLoop.php

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

122-
if ($timers->contains($timer)) {
122+
if ($timers->offsetExists($timer)) {
123123
$that->cancelTimer($timer);
124124
}
125125
};
126126

127127
$event = \uv_timer_init($this->uv);
128-
$this->timers->attach($timer, $event);
128+
$this->timers->offsetSet($timer, $event);
129129
\uv_timer_start(
130130
$event,
131131
$this->convertFloatSecondsToMilliseconds($interval),
@@ -149,7 +149,7 @@ public function addPeriodicTimer($interval, $callback)
149149

150150
$interval = $this->convertFloatSecondsToMilliseconds($interval);
151151
$event = \uv_timer_init($this->uv);
152-
$this->timers->attach($timer, $event);
152+
$this->timers->offsetSet($timer, $event);
153153
\uv_timer_start(
154154
$event,
155155
$interval,
@@ -167,7 +167,7 @@ public function cancelTimer(TimerInterface $timer)
167167
{
168168
if (isset($this->timers[$timer])) {
169169
@\uv_timer_stop($this->timers[$timer]);
170-
$this->timers->detach($timer);
170+
$this->timers->offsetUnset($timer);
171171
}
172172
}
173173

0 commit comments

Comments
 (0)