Skip to content

Commit

Permalink
Attempt to use the value's discrim property as the key if offset is null
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Jan 21, 2025
1 parent 2e8f09b commit 6248c87
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Discord/Helpers/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6248c87

Please sign in to comment.