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: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:
Status: Open Package: Date/time related
PHP Version: 5.5.14 OS: ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mathieu at rochette dot cc
New email:
PHP Version: OS:

 

 [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
 [2019-10-06 22:15 UTC] aleh dot kashnikau at gmail dot com
Bug is still present in 7 version: https://3v4l.org/uk3fZ
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Oct 19 04:01:27 2019 UTC