|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 09:00:01 2025 UTC |
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.