Bug #70975 [Opn->Nab]: DatePeriod->interval:The DateInterval object has not been correctly initialized
| From: | cmb@php.net | Date: | Tue, 14 Jun 2016 10:59:29 +0000 |
| Subject: | Bug #70975 [Opn->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-201596@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
Updated by: cmb@php.net
Reported by: marc at mabe dot berlin
Summary: DatePeriod->interval:The DateInterval object has not
been correctly initialized
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>.
Previous Comments:
------------------------------------------------------------------------
[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