From:
Operating system: Linux
PHP version: 5.3.8
Package: Date/time related
Bug Type: Bug
Bug description:DateTime::__construct throws Exception even when timezone is
specified
Description:
------------
The DateTime constructor throws an Exception warning that it is not safe to
rely
on the system's timezone settings if you try to construct a DateTime object
and
haven't somehow specified a timezone, whether by using
date_default_timezone_set,
the date.timezone setting, or the $timezone argument of DateTime itself.
However, there is another way to specify the timezone for a DateTime
object, by
passing a time string which includes a timezone as the first argument to
the
constructor. When such a string is given, the $timezone argument is ignored
and
the timezone given in the string is always used.
However, this doesn't prevent the Exception from being thrown, even though
a
timezone is being specified. To avoid the Exception, you have to have a
default
timezone set, or you have to pass a DateTimeZone as the second argument,
even
though neither would actually be used for creating the object.
Test script:
---------------
<?php
ini_set('date.timezone', NULL);
try {
$date = new DateTime('2011-08-28T00:00:00+0000');
echo $date->format('O');
} catch (Exception $e) {
echo 'Exception thrown.';
}
echo PHP_EOL;
date_default_timezone_set('America/New_York');
try {
$date = new DateTime('2011-08-28T00:00:00+0000');
echo $date->format('O');
} catch (Exception $e) {
echo 'Exception thrown.';
}
Expected result:
----------------
+0000
+0000
Actual result:
--------------
Exception thrown.
+0000
--
Edit bug report at https://bugs.php.net/bug.php?id=55527&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=55527&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=55527&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=55527&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=55527&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=55527&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=55527&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=55527&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=55527&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=55527&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=55527&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=55527&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=55527&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=55527&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=55527&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=55527&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=55527&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=55527&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=55527&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=55527&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=55527&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=55527&r=mysqlcfg