php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81106 Regression in 8.1: add() now truncate ->f
Submitted: 2021-06-04 17:41 UTC Modified: 2021-08-08 16:28 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: kylekatarnls at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: master-Git-2021-06-04 (Git) OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kylekatarnls at gmail dot com
New email:
PHP Version: OS:

 

 [2021-06-04 17:41 UTC] kylekatarnls at gmail dot com
Description:
------------
An interval with ->f = 1.234 was previously understood as 1.234 second when using in DateTime::add() which sounds pretty consistent.

Now it's understood as 0.234 which feels pretty unsafe. Moreover, if we dump the interval, we see ->f value is still 1.234.

If ->f can now longer be >= 1, it would rather need to throw an exception rather than accepting it and be interpreted differently regarding where it's used.

Test script:
---------------
$dateInterval = new DateInterval('PT0S');
$dateInterval->f = 1.234;

echo (new DateTimeImmutable('2000-01-01 00:00:00'))->add($dateInterval)->format('Y-m-d H:i:s.u');

Expected result:
----------------
2000-01-01 00:00:01.234000

(What we got for PHP <= 8.0)

Actual result:
--------------
2000-01-01 00:00:00.234000

(What we get now with master branch)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-04 18:22 UTC] kylekatarnls at gmail dot com
For the record, it's not consistent with what happen with ->s = 78 which properly add 78 seconds in both PHP 8.0 and 8.1
 [2021-06-04 19:08 UTC] kylekatarnls at gmail dot com
Me again, it's going very unexpected when using negative number:

->f = -1.234

=> Add 0.766 seconds
 [2021-06-09 18:31 UTC] patrickallaert@php.net
-Assigned To: +Assigned To: derick
 [2021-08-08 16:28 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2021-08-08 16:28 UTC] derick@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

Fixed for 8.1.0beta3.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 08:01:28 2024 UTC