Bug #73239 [Ver]: DateTime constructor throws exceptions when it should not
| From: | derick@php.net | Date: | Thu, 06 Oct 2016 16:05:26 +0000 |
| Subject: | Bug #73239 [Ver]: DateTime constructor throws exceptions when it should not | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204515@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73239&edit=1
ID: 73239
Updated by: derick@php.net
Reported by: alec@php.net
Summary: DateTime constructor throws exceptions when it
should not
Status: Verified
Type: Bug
Package: Date/time related
PHP Version: 7.0.11
Block user comment: N
Private report: N
New Comment:
IMO, this message is correct. If you add some *broken* data, you very much should get a notice about
this. And Exceptions is how a constructor signals this.
Previous Comments:
------------------------------------------------------------------------
[2016-10-04 15:56:04] cmb@php.net
Considering that using date_default_timezone_set() instead of
ini_set() does not cause the DateTime constructor to throw an
exception[1], this inconsistency[2] doesn't make sense.
[1] <https://3v4l.org/NDHgI>
[2] <https://3v4l.org/Rli3e>
------------------------------------------------------------------------
[2016-10-04 13:23:00] alec@php.net
Description:
------------
When invalid (or empty date.timezone) is configured DateTime constructor will throw an exception
instead of a warning.
On PHP7 I can reproduce the issue with invalid date.timezone. It works with empty date.timezone, but
it might be environment specific. I have user reports that it throws exception with empty setting.
E.g.
PHP Fatal error: Uncaught exception 'Exception' with message
'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You
are required to use the date.timezone setting or the date_default_timezone_set() function. In case
you used any of those methods and you are still getting this warning, you most likely misspelled the
timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone
to select your timezone.' in ...
This should not happen.The point of falling back to 'UTC' here is exactly to not throw an
exception, no?
Test script:
---------------
ini_set('date.timezone', 'dummy');
$dt = new DateTime('now');
Expected result:
----------------
no exception.
Actual result:
--------------
PHP Fatal error: Uncaught Exception: DateTime::__construct(): Invalid date.timezone value
'dummy', we selected the timezone 'UTC' for now. in ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73239&edit=1