-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
Not Needed
-
The method MongoDB\BSON\UTCDateTime::toDateTime() returns a mutable DateTime instance. The community pushes for using ImmutableDateTime as much as possible.
- https://www.reddit.com/r/PHP/comments/w7v4pb/deprecating_the_mutable_datetime_class/
- https://blog.devgenius.io/stop-using-datetime-in-php-66df3d731875
- https://www.nikolaposa.in.rs/blog/2019/07/01/stop-using-datetime/
Currently, to get a DateTimeImmutable object from an UTCDateTime, developers have to do that:
$date = new UTCDateTime();
$dateTime = ImmutableDateTime::fromMutable($date->toDateTime());
Proposed implementations:
Add a method:
$dateTime = $date->toDateTimeImmutable();
Add a argument:
$dateTime = $date->toDateTime(mutable: false);
We can change the default value of mutable in 2.0 to return an immutable object by default. This change can be announced by deprecating not-passing an argument to the method.
- related to
-
PHPC-2417 Add UTCDateTimeInterface::toDateTimeImmutable
- Closed