Bug->Doc #76620 [Nab->ReO]: DatePeriod::getEndDate() drops reference to the end date DateTime object
| From: | cmb@php.net | Date: | Fri, 13 Jul 2018 16:53:31 +0000 |
| Subject: | Bug->Doc #76620 [Nab->ReO]: DatePeriod::getEndDate() drops reference to the end date DateTime object | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-15882@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76620&edit=1
ID: 76620
Updated by: cmb@php.net
Reported by: jerry at jmweb dot net
Summary: DatePeriod::getEndDate() drops reference to the end
date DateTime object
-Status: Not a bug
+Status: Re-Opened
-Type: Bug
+Type: Documentation Problem
Package: Date/time related
Operating System: Win7 64bit
PHP Version: 7.2.7
-Assigned To: cmb
+Assigned To:
Block user comment: N
Private report: N
New Comment:
Firstly, to confirm your assumption, use
var_dump(
$period->getEndDate() === $period->getEndDate()
);
::add() returns a new DateTime object anyway.
> Can you show me where this is stated in the documentation?
It is not explicitly documented.
> And if it is not modifiable, whats the purpose of instantiating
> with DateTimeImmutable?
DateTime as well as DateTimeImmutable are supported for
convenience, and for historic reasons.
Previous Comments:
------------------------------------------------------------------------
[2018-07-13 14:49:10] jerry at jmweb dot net
First and foremost, thank you for working on the PHP project.
Can you show me where this is stated in the documentation? And if it is not modifiable, whats the
purpose of instantiating with DateTimeImmutable?
------------------------------------------------------------------------
[2018-07-13 14:37:12] cmb@php.net
As said above.
------------------------------------------------------------------------
[2018-07-13 14:36:45] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The end date is not supposed to be modifiable.
------------------------------------------------------------------------
[2018-07-13 14:20:41] jerry at jmweb dot net
Description:
------------
When DatePeriod is instantiated with DateTime objects (as opposed to DateTimeImmutable objects), the
getEndDate() instance method does not return a reference to the object's internal end date
DateTime object.
Test script:
---------------
$period = new DatePeriod(
new DateTime( '2018-01-01' ),
new DateInterval( 'P1D' ),
new DateTime( '2018-01-02' )
);
var_dump(
$period->getEndDate()->add( new DateInterval( 'P1D' ) ) ===
$period->getEndDate()
);
Expected result:
----------------
bool(true)
Actual result:
--------------
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76620&edit=1