Bug #67634 [Com]: getTimestamp() modify instance of DateTimeImmutable

From: Date: Sun, 06 Oct 2019 22:15:02 +0000
Subject: Bug #67634 [Com]: getTimestamp() modify instance of DateTimeImmutable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223101@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67634&edit=1

 ID:                 67634
 Comment by:         aleh dot kashnikau at gmail dot com
 Reported by:        mathieu at rochette dot cc
 Summary:            getTimestamp() modify instance of DateTimeImmutable
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   ubuntu
 PHP Version:        5.5.14
 Block user comment: N
 Private report:     N

 New Comment:

Bug is still present in 7 version: https://3v4l.org/uk3fZ


Previous Comments:
------------------------------------------------------------------------
[2014-10-16 19:19:41] sjon at hortensius dot net

This bug is present in all php-versions including php7:

http://3v4l.org/M5Hcu

The bug can also be simplified to http://3v4l.org/ShFpG; where
it shows that the ->modify() call is irrelevant

------------------------------------------------------------------------
[2014-07-16 15:28:40] mathieu at rochette dot cc

Description:
------------
calling getTimestamp() on an instance of a DateTimeImmutable modify it (and return the modified date
timestamp).

calling format('U') does not modify the date

Test script:
---------------
<?php

$date = new DateTimeImmutable('2014-05');

$date2 = $date->modify('first day of next month midnight - 1 second');

var_dump($date2->format('c'));
var_dump($date2->format('U'));
var_dump($date2->format('c'));
var_dump($date2->getTimestamp());
var_dump($date2->format('U'));
var_dump($date2->format('c'));


Expected result:
----------------
string(25) "2014-05-31T23:59:59+00:00"
string(10) "1401580799"
string(25) "2014-05-31T23:59:59+00:00"
int(1401580799)
string(10) "1401580799"
string(25) "2014-05-31T23:59:59+00:00"


Actual result:
--------------
string(25) "2014-05-31T23:59:59+00:00"
string(10) "1401580799"
string(25) "2014-05-31T23:59:59+00:00"
int(1398988799)
string(10) "1398988799"
string(25) "2014-05-01T23:59:59+00:00"


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



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


Thread (4 messages)

« previous php.bugs (#223101) next »