Skip to content

Commit 8777cc4

Browse files
committed
refactor: rename objectToArray to entityToArray and preserve keys in iterator_to_array
- Rename objectToArray() to entityToArray() since it only handles Entity - Add false parameter to iterator_to_array() to preserve numeric keys when materializing Traversable objects in toIterable() Per review feedback from @michalsn on #10226.
1 parent c537aed commit 8777cc4

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎system/Helpers/Array/ArrayHelper.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ private static function valueExists(array|object $data, string $key): bool
469469
return isset($data[$key]);
470470
}
471471

472-
$array = self::objectToArray($data);
472+
$array = self::entityToArray($data);
473473

474474
if ($array !== null) {
475475
return isset($array[$key]);
@@ -495,7 +495,7 @@ private static function value(array|object $data, string $key): mixed
495495
return $data[$key];
496496
}
497497

498-
$array = self::objectToArray($data);
498+
$array = self::entityToArray($data);
499499

500500
if ($array !== null) {
501501
return $array[$key];
@@ -517,7 +517,7 @@ private static function value(array|object $data, string $key): mixed
517517
/**
518518
* @return array<array-key, mixed>|null
519519
*/
520-
private static function objectToArray(object $data): ?array
520+
private static function entityToArray(object $data): ?array
521521
{
522522
if ($data instanceof Entity) {
523523
return $data->toArray();
@@ -537,14 +537,14 @@ private static function objectToArray(object $data): ?array
537537
*/
538538
private static function toIterable(object $data): array
539539
{
540-
$array = self::objectToArray($data);
540+
$array = self::entityToArray($data);
541541

542542
if ($array !== null) {
543543
return $array;
544544
}
545545

546546
if ($data instanceof Traversable) {
547-
return iterator_to_array($data);
547+
return iterator_to_array($data, false);
548548
}
549549

550550
return get_object_vars($data);

0 commit comments

Comments
 (0)