Skip to content

Commit c597ffa

Browse files
committed
Message
1 parent 7864b63 commit c597ffa

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/Database/Document.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public function __construct(array $input = [])
4646
}
4747

4848
foreach ($value as $childKey => $child) {
49-
// Only wrap array children that look like sub-documents. Non-array elements
50-
// (e.g. MongoDB\BSON\UTCDateTime in a datetime array, scalars, other objects)
51-
// are not array-accessible, so isset($child['$id']) would fatal on them.
49+
// An array value is either a list of nested sub-documents or a list of
50+
// plain items (dates, numbers, strings): wrap the former, leave the latter.
51+
// is_array() tells them apart and avoids array-accessing a non-array
52+
// value (e.g. a UTCDateTime), which would otherwise fatal.
5253
if (\is_array($child) && (isset($child['$id']) || isset($child['$collection']))) {
5354
$value[$childKey] = new self($child);
5455
}

0 commit comments

Comments
 (0)