php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75182 Should DateTimeImmutable/DateTime throw a exception
Submitted: 2017-09-11 09:28 UTC Modified: 2021-10-01 16:54 UTC
From: nyamsprod at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-09-11 09:28 UTC] nyamsprod at gmail dot com
Description:
------------
in PHP7.1+ DateInterval can take the number of microseconds, as a fraction of a second with the DateInterval::f public property.

If DateInterval::f is set with a value greater than 1, DateInterval accepts it without warning. If we modify a DateTimeInterface object with this "invalid" DateInterval, a invalid DateTimeInterface object is returned.

see https://3v4l.org/PcEMi


Test script:
---------------
$interval = new DateInterval('PT1S');
$interval->f = 500000;  // excepted an Exception
var_dump(date_create_immutable('2017-03-15')->add($interval));
// expected an OverflowException or a valid DateTimeInterface 

returns an Invalid DateTimeInterface

object(DateTimeImmutable)#3 (3) {
 ["date"]=> string(31) "2017-03-15 00:00:03.-2147483648"
 ["timezone_type"]=> int(3)
 ["timezone"]=> string(16) "Europe/Amsterdam"
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-01 16:54 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-10-01 16:54 UTC] cmb@php.net
This is fixed as of PHP 7.3.12 with the usual silent overflow
semantics.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC