From 6248c87e20b40a7b161fd210e49c69b9a6fd4626 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Tue, 21 Jan 2025 08:55:54 -0500 Subject: [PATCH] Attempt to use the value's discrim property as the key if offset is null --- src/Discord/Helpers/CollectionTrait.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Discord/Helpers/CollectionTrait.php b/src/Discord/Helpers/CollectionTrait.php index 26e477c6c..039aa2443 100644 --- a/src/Discord/Helpers/CollectionTrait.php +++ b/src/Discord/Helpers/CollectionTrait.php @@ -587,6 +587,15 @@ public function offsetGet($offset) */ public function offsetSet($offset, $value): void { + // Attempt to use the value's discrim property as the key if offset is null + if (is_null($offset)) { + if (is_object($value) && isset($value->{$this->discrim})) { + $offset = $value->{$this->discrim}; + } elseif (is_array($value) && isset($value[$this->discrim])) { + $offset = $value[$this->discrim]; + } + } + $this->items[$offset] = $value; }