Bug #70975 [Nab]: DatePeriod->interval:The DateInterval object has not been correctly initialized

From: Date: Thu, 16 Jun 2016 19:09:35 +0000
Subject: Bug #70975 [Nab]: DatePeriod->interval:The DateInterval object has not been correctly initialized
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201682@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70975&edit=1

 ID:                 70975
 User updated by:    marc at mabe dot berlin
 Reported by:        marc at mabe dot berlin
 Summary:            DatePeriod->interval:The DateInterval object has not
                     been correctly initialized
 Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 PHP Version:        Irrelevant
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2016-06-14 10:59:26] 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>.

------------------------------------------------------------------------
[2015-11-26 10:57:20] 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"
}



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=70975&edit=1


Thread (5 messages)

« previous php.bugs (#201682) next »