[php-src] Issue #8153: DateTime->sub produces different value than on older versions

From: Date: Thu, 31 Mar 2022 08:19:51 +0000
Subject: [php-src] Issue #8153: DateTime->sub produces different value than on older versions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240594@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8153
Comment Author: hormus

@cmb69 If through diff I create DateInterval or from PHP >= 7.1.7 clone DateInterval
DateInterval::sub works as expected. Maybe from php 8.1 DateInterval gets the reference from some
cache or oblivious even if it is setter afterwards.
`<?php
//PHP >= 7.1.7 clone DateInterval https://bugs.php.net/bug.php?id=70975
$date1 = new \DateTime('2022-03-30 00:00:00.000100', new
\DateTimeZone('Europe/Rome'));
$delta = new \DateInterval('PT0S');
$clone = (clone $delta);
$clone->f = 0.0001;
$date2 = new \DateTime('2022-03-30 00:00:00.000000', new
\DateTimeZone('Europe/Rome'));
$diff = $date2->diff($date1);
    $date2->setTimezone(new \DateTimeZone('UTC'));
    $date2->sub($clone);
    $date1->setTimezone(new \DateTimeZone('UTC'));
    $date1->sub($diff);
    $date1->sub($diff);
var_dump($date2, $date1, $clone, $diff);`


Thread (1 message)

  • hormus
« previous php.bugs (#240594) next »