php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67634 getTimestamp() modify instance of DateTimeImmutable
Submitted: 2014-07-16 15:28 UTC Modified: -
Votes:25
Avg. Score:3.1 ± 1.9
Reproduced:8 of 19 (42.1%)
Same Version:3 (37.5%)
Same OS:5 (62.5%)
From: mathieu at rochette dot cc Assigned:
Status: Open Package: Date/time related
PHP Version: 5.5.14 OS: ubuntu
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-07-16 15:28 UTC] 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"

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-16 19:19 UTC] 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
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC