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: 2016-06-16 22:29 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:
Status: Re-Opened Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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. :)
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 18:01:23 2020 UTC