Bug #67634 [Com]: getTimestamp() modify instance of DateTimeImmutable
| From: | sjon at hortensius dot net | Date: | Thu, 16 Oct 2014 19:19:41 +0000 |
| Subject: | Bug #67634 [Com]: getTimestamp() modify instance of DateTimeImmutable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188145@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: sjon at hortensius dot net
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:
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
Previous Comments:
------------------------------------------------------------------------
[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