php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70975 DatePeriod->interval:The DateInterval object has not been correctly initialized
Submitted: 2015-11-26 10:57 UTC Modified: 2021-01-06 18:09 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: marc at mabe dot berlin Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: Irrelevant OS:
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: marc at mabe dot berlin
New email:
PHP Version: OS:

 

 [2015-11-26 10:57 UTC] marc at mabe dot berlin
Description:
------------
If using the DatePeriod->interval the DateInterval object has not been correctly initialized by its constructor.

With this bug it is impossible to take a DatePeriod object as one argument in a function :(

Test script:
---------------
<?php

$start    = new DateTime('2015-09-01');
$end      = new DateTime('2015-09-02');
$interval = new DateInterval('P1D');
$period   = new DatePeriod($start, $interval, $end); 

foreach ($period as $current) {
    $currentEnd = clone $current;
    $currentEnd->add($period->interval);
    var_dump($current, $currentEnd);
}

Expected result:
----------------
object(DateTime)#6 (3) {
    ["date"]=> string(26) "2015-09-01 00:00:00.000000"
    ["timezone_type"]=> int(3)
    ["timezone"]=> string(16) "Europe/Amsterdam"
}
object(DateTime)#7 (3) {
    ["date"]=> string(26) "2015-09-02 00:00:00.000000"
    ["timezone_type"]=> int(3)
    ["timezone"]=> string(16) "Europe/Amsterdam"
}


Actual result:
--------------
Warning: DateTime::add(): The DateInterval object has not been correctly initialized by its constructor in /in/tmZN9 on line 10
object(DateTime)#6 (3) {
    ["date"]=> string(26) "2015-09-01 00:00:00.000000"
    ["timezone_type"]=> int(3)
    ["timezone"]=> string(16) "Europe/Amsterdam"
}
object(DateTime)#7 (3) {
    ["date"]=> string(26) "2015-09-01 00:00:00.000000"
    ["timezone_type"]=> int(3)
    ["timezone"]=> string(16) "Europe/Amsterdam"
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-14 10:59 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-06-14 10:59 UTC] cmb@php.net
Don't use undocumented properties of built-in objects; use the
public API instead, in this case DatePeriod::getDateInterval().
Works as expected: <https://3v4l.org/iD6hn>.
 [2016-06-16 19:09 UTC] marc at mabe dot berlin
I' totally ok with that using the public getter methods.
But as if the public properties are not working as expected it's still a bug.

There are two possibilities in my opinion:
1. fix the public properties
2. or make them private
 [2016-06-16 22:29 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened -Assigned To: cmb +Assigned To:
 [2016-06-16 22:29 UTC] cmb@php.net
Okay, re-opening. I'm still not convinced that there is a bug, but
I'm leaving that for others to decide. :)
 [2021-01-06 18:09 UTC] cmb@php.net
-Status: Re-Opened +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2021-01-06 18:09 UTC] cmb@php.net
Closing as duplicate of bug #74639 (fixed as of PHP 7.1.7).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 12:01:29 2024 UTC