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: 2019-10-23 13:34 UTC
Votes:28
Avg. Score:3.2 ± 1.9
Reproduced:9 of 21 (42.9%)
Same Version:3 (33.3%)
Same OS:6 (66.7%)
From: mathieu at rochette dot cc Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: 5.5.14 OS: ubuntu
Private report: No CVE-ID: None
 [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

Pull Requests

Pull requests:

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
 [2019-10-06 22:15 UTC] aleh dot kashnikau at gmail dot com
Bug is still present in 7 version: https://3v4l.org/uk3fZ
 [2019-10-23 13:34 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2019-10-23 13:34 UTC] cmb@php.net
This bug is already been fixed as of PHP 7.0.4, see <https://3v4l.org/M5Hcu>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 23:01:26 2024 UTC