3
What exactly is the method for DateTime::createFromImmutable()
?
Implemented according to the release note of version 7.3.0 of PHP.
3
What exactly is the method for DateTime::createFromImmutable()
?
Implemented according to the release note of version 7.3.0 of PHP.
3
Attending to the request, the method will serve for you to create an object DateTime
from an object DateTimeImmutable
.
$immutable = new DateTimeImmutable(); // objeto imutável
$mutable = DateTime::createFromImmutable($immutable); // objeto mutável
This method had already been created before and was removed later. It supports what exists in reverse. That is, create a DateTimeImmutable
from a DateTime
in this way:
$mutable = new DateTime(); // objeto mutável
$immutable = DateTimeImmutable::createFromMutable($mutable); // objeto imutável
Take an example how it could be done before this method:
$dateTime = new \DateTime();
$dateTime->setTimestamp($dateTimeImmutable->getTimestamp());
Browser other questions tagged php datetime php-7 immutability
You are not signed in. Login or sign up in order to post.