php.net |  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: odoucet@php.net Assigned: aharvey (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.2 OS:
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: odoucet@php.net
New email:
PHP Version: OS:

 

 [2010-07-19 16:03 UTC] odoucet@php.net
Description:
------------
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:
http://www.php.net/manual/en/datetime.settimestamp.php#Notes
"Passing a Unix timestamp to DateTime::__construct()  is an alternative when using PHP 5.2."



Test script:
---------------
<?php
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'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-19 17:23 UTC] derick@php.net
-Type: Bug +Type: Documentation Problem
 [2010-07-19 23:10 UTC] dtajchreber@php.net
-Assigned To: +Assigned To: dtajchreber
 [2010-07-19 23:10 UTC] dtajchreber@php.net
<?php
var_dump(new DateTime('@' . time()));
 [2010-07-19 23:13 UTC] dtajchreber@php.net
-Status: Assigned +Status: Bogus
 [2010-07-19 23:13 UTC] dtajchreber@php.net
After looking through, it seems it's documented here: http://www.php.net/manual/en/datetime.formats.compound.php
 [2010-07-20 04:44 UTC] aharvey@php.net
-Status: Bogus +Status: Assigned -Assigned To: dtajchreber +Assigned To: aharvey
 [2010-07-20 04:44 UTC] aharvey@php.net
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] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=301411
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] aharvey@php.net
-Status: Assigned +Status: Closed
 [2010-07-20 06:25 UTC] aharvey@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC