-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
PHP Drivers
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
Setting and then unsetting a dynamic property on `MongoDB\BSON\ObjectId` changes its subsequent `foreach` behavior. Before the operation, iteration yields the synthetic oid property. Afterwards, iteration yields nothing, even though the `ObjectId` value is unchanged.
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
function iterationKeys(object $object): array {
$keys = [];
foreach ($object as $key => $value) {
$keys[] = $key;
}
return $keys;
}
$oid = new MongoDB\BSON\ObjectId('507f1f77bcf86cd799439011');
echo json_encode(iterationKeys($oid)), "\n";
$oid->foo = 'x';
unset($oid->foo);
echo json_encode(iterationKeys($oid)), "\n";
echo (string) $oid, "\n";