Doc #52378 [Asn->Csd]: new DateTime(time()) failed and should not
| From: | aharvey@php.net | Date: | Tue, 20 Jul 2010 04:25:32 +0000 |
| Subject: | Doc #52378 [Asn->Csd]: new DateTime(time()) failed and should not | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-4715@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52378&edit=1
ID: 52378
Updated by: aharvey@php.net
Reported by: odoucet@php.net
Summary: new DateTime(time()) failed and should not
-Status: Assigned
+Status: Closed
Type: Documentation Problem
Package: Date/time related
PHP Version: 5.3.2
Assigned To: aharvey
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-07-20 06:25:17] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&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 04:44:01] 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-19 23:13:31] dtajchreber@php.net
After looking through, it seems it's documented here:
http://www.php.net/manual/en/datetime.formats.compound.php
------------------------------------------------------------------------
[2010-07-19 23:10:43] dtajchreber@php.net
<?php
var_dump(new DateTime('@' . time()));
------------------------------------------------------------------------
[2010-07-19 16:03:07] 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'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52378&edit=1