From faa23a05f106f890dc8b61e33e1c827b7c3c1d59 Mon Sep 17 00:00:00 2001 From: Marin Binzari Date: Mon, 11 May 2026 13:37:40 +0300 Subject: [PATCH 1/2] Fix "Undefined array key 0" warning in MultiRPC constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `self::$freeRelays` is not guaranteed to be 0-indexed: entries are removed via `unset(self::$freeRelays[$relayIndex])` in `occupyRelay()` and `occupyRelayAsync()` (lines 171, 194), and PHP's auto-increment retains the highest key ever used when appending. After enough churn in a long-running worker (e.g. RoadRunner), the static array can end up with keys like `[1 => ..., 3 => ...]` — `count() > 0` holds, but `self::$freeRelays[0]` raises `Warning: Undefined array key 0`. Switch to `array_key_first()`, mirroring the `$occupiedRelays` branch two lines below. --- src/RPC/MultiRPC.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/RPC/MultiRPC.php b/src/RPC/MultiRPC.php index 2e70e99..c51689b 100644 --- a/src/RPC/MultiRPC.php +++ b/src/RPC/MultiRPC.php @@ -77,8 +77,10 @@ public function __construct( } // Check if the existing relays (if any) and the new relays are of the same type. + // Note: self::$freeRelays is not guaranteed to be 0-indexed — entries are removed + // via unset() in occupy*() and PHP keeps the highest key ever used on append. if (\count(self::$freeRelays) > 0) { - $existingRelay = self::$freeRelays[0]; + $existingRelay = self::$freeRelays[\array_key_first(self::$freeRelays)]; } elseif (\count(self::$occupiedRelays) > 0) { $existingRelay = self::$occupiedRelays[\array_key_first(self::$occupiedRelays)]; } else { From c269c833fb4f62418ed5373030307a0aa083bdb6 Mon Sep 17 00:00:00 2001 From: Marin Binzari Date: Mon, 11 May 2026 13:57:43 +0300 Subject: [PATCH 2/2] remove comment --- src/RPC/MultiRPC.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/RPC/MultiRPC.php b/src/RPC/MultiRPC.php index c51689b..b8d5dfe 100644 --- a/src/RPC/MultiRPC.php +++ b/src/RPC/MultiRPC.php @@ -77,8 +77,6 @@ public function __construct( } // Check if the existing relays (if any) and the new relays are of the same type. - // Note: self::$freeRelays is not guaranteed to be 0-indexed — entries are removed - // via unset() in occupy*() and PHP keeps the highest key ever used on append. if (\count(self::$freeRelays) > 0) { $existingRelay = self::$freeRelays[\array_key_first(self::$freeRelays)]; } elseif (\count(self::$occupiedRelays) > 0) {