php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #76620 DatePeriod::getEndDate() drops reference to the end date DateTime object
Submitted: 2018-07-13 14:20 UTC Modified: 2018-07-13 16:53 UTC
From: jerry at jmweb dot net Assigned:
Status: Re-Opened Package: Date/time related
PHP Version: 7.2.7 OS: Win7 64bit
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jerry at jmweb dot net
New email:
PHP Version: OS:

 

 [2018-07-13 14:20 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-13 14:36 UTC] 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:37 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-07-13 14:37 UTC] cmb@php.net
As said above.
 [2018-07-13 14:49 UTC] 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 16:53 UTC] cmb@php.net
-Status: Not a bug +Status: Re-Opened -Type: Bug +Type: Documentation Problem -Assigned To: cmb +Assigned To:
 [2018-07-13 16:53 UTC] cmb@php.net
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.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Oct 16 20:01:27 2018 UTC