|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52378 new DateTime(time()) failed and should not
Submitted: 2010-07-19 16:03 UTC Modified: 2010-07-20 06:25 UTC
From: Assigned: aharvey (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
16 + 45 = ?
Subscribe to this entry?

 [2010-07-19 16:03 UTC]
Creating a new DateTime object with a unix timestamp failed with error  
Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1279547855) at position 8 (5): Unexpected character'

If this is expected behaviour, this should be written in documentation and DateTime::setTimestamp() should be fixed:
"Passing a Unix timestamp to DateTime::__construct()  is an alternative when using PHP 5.2."

Test script:
var_dump(new DateTime(time()));

Expected result:
no fatal error :)

Actual result:
Fatal error:  Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1279547855) at position 8 (5): Unexpected character'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-19 17:23 UTC]
-Type: Bug +Type: Documentation Problem
 [2010-07-19 23:10 UTC]
-Assigned To: +Assigned To: dtajchreber
 [2010-07-19 23:10 UTC]
var_dump(new DateTime('@' . time()));
 [2010-07-19 23:13 UTC]
-Status: Assigned +Status: Bogus
 [2010-07-19 23:13 UTC]
After looking through, it seems it's documented here:
 [2010-07-20 04:44 UTC]
-Status: Bogus +Status: Assigned -Assigned To: dtajchreber +Assigned To: aharvey
 [2010-07-20 04:44 UTC]
The DateTime::setTimestamp() documentation does advertise passing a timestamp directly to new DateTime(), though, which is unfortunate.

I'll tidy it up.
 [2010-07-20 06:25 UTC]
Automatic comment from SVN on behalf of aharvey
Log: Per doc bug #52378 (new DateTime(time()) failed and should not), clarified how
you can emulate the functionality of DateTime::setTimestamp() in PHP 5.2 with
an example.
 [2010-07-20 06:25 UTC]
-Status: Assigned +Status: Closed
 [2010-07-20 06:25 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 13:01:27 2024 UTC