What exactly does the DateTime :: createFromImmutable () method serve?

3

What exactly is the DateTime::createFromImmutable() method for? Implemented according to release note of PHP version 7.3.0.

    
asked by anonymous 21.12.2018 / 02:36

1 answer

3

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());
    
21.12.2018 / 03:43