What exactly is the DateTime::createFromImmutable()
method for?
Implemented according to release note of PHP version 7.3.0.
What exactly is the DateTime::createFromImmutable()
method for?
Implemented according to release note of PHP version 7.3.0.
Given the request , the method will help you create a DateTime
object from one object DateTimeImmutable
.
$immutable = new DateTimeImmutable(); // objeto imutável
$mutable = DateTime::createFromImmutable($immutable); // objeto mutável
This method had already been created before and was later removed. It supports what exists in reverse. That is, create a DateTimeImmutable
from a DateTime
like this:
$mutable = new DateTime(); // objeto mutável
$immutable = DateTimeImmutable::createFromMutable($mutable); // objeto imutável
See an example of how it could be done before this method:
$dateTime = new \DateTime();
$dateTime->setTimestamp($dateTimeImmutable->getTimestamp());